重点内容
1.http 超文本文件传输协议
2.规则,协议:由一些人规定遵循的规则,然后使用HTTP方式请求文件的必须遵循这个规则(协议)
2.cookie
<script type="text/javascript">
function setJSCookie(key ,value, day){
var dat = new Date();
dat.setTime(dat.getTime() + day * 24 * 3600 * 1000);
document.cookie = key + "=" + value + ";expires=" + dat.toUTCString();
}
setJSCookie("wang" ,"111111", 2);
function getJSCookie(key){
var arr = document.cookie.split("; ");
for(var i = 0; i < arr.length; i++){
var str = arr[i];
var theArr = str.split("=");
if(theArr[0] == key){
console.log(theArr[1]);
}
}
}
getJSCookie("wang");
function removeJSCookie(key){
var nowD = new Date();
nowD.setTime(nowD.getTime() - 1000);
document.cookie = key + "=" + "xx;expires="+ nowD.toUTCString();
}
removeJSCookie("wang");
</script>
2.封装cookie
"use static";
var obj = {
"setJSCookie" : setJSCookie,
"getJSCookie" : getJSCookie,
"removeJSCookie" : removeJSCookie
}
function setJSCookie(key, value, day) {
var dat = new Date();
dat.setTime(dat.getTime() + day * 24 * 3600 * 1000);
document.cookie = key + "=" + value + ";expires=" + dat.toUTCString();
}
function getJSCookie(key) {
var arr = document.cookie.split("; ");
for(var i = 0; i < arr.length; i++) {
var str = arr[i];
var theArr = str.split("=");
if(theArr[0] == key) {
console.log(theArr[1]);
}
}
}
function removeJSCookie(key) {
var nowD = new Date();
nowD.setTime(nowD.getTime() - 1000);
document.cookie = key + "=" + "xx;expires=" + nowD.toUTCString();
}
----------
测试
<script src="wqq.js" ></script>
<script type="text/javascript">
obj.setJSCookie("name","lisi",2);
</script>
3.php设置/读取cookie
<?php
$a = md5(111111);
setcookie("password",$a,time()+3600*24,"/",localhost,0);
var_dump($_COOKIE['password']);
?>
4.session之我见
1.sesseon.php
<?php
session_start();
$_SESSION["name"] = "张三丰";
?>
2.getsession.php
<?php
header("Content-type: text/html; charset=utf-8");
session_start();
echo $_SESSION['name'];
?>
guid
function create_guid() {
$charid = strtoupper(md5(uniqid(mt_rand(), true)));
$hyphen = chr(45);
$uuid =
substr($charid, 0, 8)
.substr($charid, 8, 4)
.substr($charid,12, 4)
.substr($charid,16, 4)
.substr($charid,20,12);
return $uuid;
}
echo create_guid();
<?php
header("content-type:text/html;charset=utf-8");
session_start();
$_SESSION["name"] = "英雄";
session_unset();
session_destroy();
?>
5.验证码
05php_use_yzm.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<form>
<input type="text" id="enter_yzm"/>
<input type="submit" value="提交验证" onclick="up()"/>
</form>
<img src="05php_yzm.php" id="yzm"/><a href="javaScript:reloadImage()">刷新</a>
<script type="text/javascript">
function reloadImage(){
var theImg = document.getElementById("yzm");
var da = new Date();
theImg.src = "05php_yzm.php?"+"timetemp=" + da.getTime();
console.log(theImg.src);
}
function up(){
var enter_yzm = document.getElementById("enter_yzm").value;
$.ajax({
type: "POST",
url: "05php_check_code.php",
data:{
"theCode":enter_yzm
},
success: function(msg){
alert(msg );
},
error:function(e){
console.log(e.statusText);
}
});
}
</script>
</body>
</html>
-----------------------------------------
05php_yzm.php
<?php
header("Content-Type: image/png");
$rand = "";
for ($i = 0; $i < 4; $i++){
$p = rand(0, 2);
switch ($p){
case 0:
$num = rand(49, 57);
$rand = $rand.chr($num);
break;
case 1:
$num = rand(97, 122);
$rand = $rand.chr($num);
break;
case 2:
$num = rand(65, 90);
$rand = $rand.chr($num);
break;
}
}
$im=imagecreatetruecolor(100,40);
$wordColor=imagecolorallocate($im,55,255,128);
for($i = 0; $i < 3; $i++){
$stringColor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imageline($im,rand(0,100),0,rand(0,100),30,$stringColor);
}
for($i = 0; $i < 200; $i++){
imagesetpixel($im, rand()%100, rand()%100, $stringColor);
}
imagestring($im, 6, rand(10,50), rand(5,15), $rand, $wordColor);
header("Content-type:image/png");
imagepng($im);
session_start();
$_SESSION["code"] = $rand;
?>
-------------------------------------------
05php_check_code.php
<?php
session_start();
$co = $_SESSION['code'];
$qCo = $_POST['theCode'];
$qCo = strtoupper($qCo);
$co = strtoupper($co);
if($co == $qCo){
echo "验证成功";
}else{
echo "验证失败";
}
?>