ALTER TABLE `locTest` ADD `user_id` INT NOT NULL AFTER `ID`
在ID列后添加非空新列user_id。用的INT数据类型,由于设置非空,之前的行会自动设置user_id为“0”。
ALTER TABLE `locTest` ADD `user_id` INT NOT NULL AFTER `ID`
在ID列后添加非空新列user_id。用的INT数据类型,由于设置非空,之前的行会自动设置user_id为“0”。
需要准备GoogleServicesFramework.apk和Google Play.apk两个文件,网上有很多。将GoogleServicesFramework复制到system/app,然后直接安装Google Play,装完不要打开。进入data/app目录下找到com.android.vending-1.apk文件,复制到system/app目录下。重启手机就可以打开登录了。
function mySendMail($recipient,$recipientName,$subject,$body){ require 'PHPMailerAutoload.php'; date_default_timezone_set("Asia/Shanghai");//设定时区东八区 $mail = new PHPMailer; $mail->CharSet ="UTF-8";//设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码 $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com'; // Specify main and backup server $mail->Port = 465; // SMTP服务器的端口号 $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '[email protected]'; // SMTP username $mail->Password = '********'; // SMTP password,谷歌邮箱若开启了两步验证要单独分配密码 $mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted $mail->From = '[email protected]'; $mail->FromName = 'no-reply'; $mail->addAddress($recipient, $recipientName); // Add a recipient, Name is optional $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->isHTML(true); // Set email format to HTML $mail->Subject = $subject; $mail->Body = $body; if(!$mail->send()) { echo '邮件发送失败'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo '邮件发送成功'; }
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); mysqli_set_charset($dbc, "utf8");
此法效果类似路由器的登录页面,会弹出一个登录页。适合一个admin的简单授权管理。结束会话(关闭浏览器)后授权即失效。
首先创建authorize.php,这样只需在需要授权的页面引用即可。内容如下:
<?php
// User name and password for authentication
$username = 'rock';
$password = 'roll';
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
($_SERVER['PHP_AUTH_USER'] != $username) || ($_SERVER['PHP_AUTH_PW'] != $password)) {
// The user name/password are incorrect so send the authentication headers
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="特征码"');//需要相同认证的页面标记
exit('<h2>Hi</h2>Display this message when user select CANCEL.');
}
?>
在需要授权的页面开始处添加:
<?php
require_once('authorize.php');
?>
需要注意的是上面这段引用,即授权代码必须放在最前面,其<?php前不能有任何字符,即使是空格也不行。
这个代码没什么太大用途,权当复习一下java,里面的例外也处理。作用就是能下载http://www.style.com/fashionshows/complete/slideshow/F2014MEN-AMCQUEEN/这个相册里的30张图。
package fatch;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
/**
*
* @author 42
*/
public class Fatch {
/**
* 本程序获取http://www.style.com/fashionshows/complete/slideshow/F2014MEN-AMCQUEEN/相册中的30张图片
* 通过查看图片属性发现其文件名有简单规律,虽不连续但是是有顺序的
* first,last是网址的前半部分和后半部分
* 先判断文件是否存在,然后将文件下载到本地
*/
public static void main(String[] args) throws MalformedURLException, IOException {
String imagesource="";
String first="http://www.style.com/fashion-shows/fall-2014-menswear/london/alexander-mcqueen/collection/_ARC0";
String last=".1366x2048.JPG";
InputStream inputStream;
byte[] getData = null;
for(int i=1,x=0;x<30&&i<=500;i++){
if(i<10){
imagesource=first+"00"+i+last;
}else if((i>=10)&&(i<100)){
imagesource=first+"0"+i+last;
}else if((i>=100)&&(i<1000)){
imagesource=first+i+last;
}
URL url = new URL(imagesource);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
try {
inputStream = conn.getInputStream(); //通过输入流获得图片数据
getData = readInputStream(inputStream); //获得图片的二进制数据
} catch (IOException ex) {
getData=null;
}
if(getData!=null){
File imageFile = new File(i+".JPG");
FileOutputStream fos = new FileOutputStream(imageFile);
fos.write(getData);
fos.close();
System.out.println(x+"picture(s) downloaded");
x++;
}
}
}
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}
}