Host: localhost:63343
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Firefox/68.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: Webstorm-91a8f251=010b5b92-7bda-48b2-a14f-b911fb6350c7; Phpstorm-9bd8916c=1d074b2f-cb88-475b-8ff1-1cc122018191
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache
HTTP/1.1 200 OK
content-type: text/html
server: PhpStorm 2019.1.1
date: Thu, 6 Jun 2019 06:33:33 GMT
X-Frame-Options: SameOrigin
X-Content-Type-Options: nosniff
x-xss-protection: 1; mode=block
cache-control: private, must-revalidate
last-modified: Thu, 6 Jun 2019 03:30:21 GMT
content-length: 669
三次握手的目的是确保连接时可靠的
header('Location:index.html')
在响应头中添加一个Location的头信息,客户端接收到这个头信息会自动跳转到头信息的地址。不能循环重定向
字面量:是代码中表述数据的一种手段
$arr = json_decode($content,true);
json_encode();
<div class="form-group">
<label for="images">海报label>
<input type="file" id="images" name="images[]" class="form-control" multiple>
div>
var_dump($_FILES['images']);
if (empty($_FILES['images'])) {
//客户端没提交音乐文件
$GLOBALS["error_msg"] = '请提交图片文件';
return;
}
$image = $_FILES['images'];
for ($i = 0; $i < count($image['name']); $i++) {
//校验是否上传成功
if ($image['error'][$i] !== UPLOAD_ERR_OK) {
$GLOBALS["error_msg"] = $image['name'][$i] . '文件上传失败';
return;
}
//校验文件类型
$allowed_type_image = array('image/png');
if (!in_array($image['type'][$i], $allowed_type_image)) {
$GLOBALS["error_msg"] = $image['name'][$i] . '文件格式非法,只能上传图片';
return;
}
//校验文件大小
if ($image['size'][$i] >= 5 * 1024 * 1024) {
$GLOBALS["error_msg"] = $image['name'][$i] . '文件超出1M';
return;
}
if ($image['size'][$i] <= 1 * 10) {
$GLOBALS["error_msg"] = $image['name'][$i] . '文件小于10K';
return;
}
//长传了文件,但还在临时目录中,开始移动
//将上传的文件重新命名
$source_images[$i] = uniqid() . '-' . $image['name'][$i];
if (!move_uploaded_file($image['tmp_name'][$i], '../file/' . $source_images[$i])) {
$GLOBALS["error_msg"] = $image['name'][$i] . '提交图片文件失败';
return;
}
}
foreach ($jsonObj as $key => $obj) {
if ($obj['id'] !== $needDeleteId) {
//break;
} else {
$index = array_search($obj, $jsonObj);
//echo "有数据" . $key.'==='.$a['title'].'、、'.$index;
//从数组中删除
$delete = array_splice($jsonObj, $index, 1);
echo ''
;
var_dump($delete);
echo '
';
var_dump($delete[0]['id']);
echo ''; var_dump($jsonObj); echo ''; } }
$connection=@mysqli_connect('127.0.0.1','root','12345678','stus');
if (!$connection){
echo '连接失败';
return;
}
@mysqli_connect 加@忽略错误信息
$query=mysqli_query($connection,'select * from stud');//返回的不是结果,返回的是查询对象
object(mysqli_result)#2 (5) {
["current_field"]=>
int(0)
["field_count"]=>
int(6)
["lengths"]=>
NULL
["num_rows"]=>
int(7)
["type"]=>
int(0)
}
mysqli_fetch_assoc($query)//以关联数组的方式从数据库取出数据
###遍历查询到的数据
$query = mysqli_query($connection, 'select * from stud');
toast($query);
$arr = array();
for ($i=0;$i<$query->num_rows;$i++){
$arr[] = mysqli_fetch_assoc($query);
}
toast($arr);
$query = mysqli_query($connection, 'select * from stud');
toast($query);
$arr = array();
$row=mysqli_fetch_assoc($query);
while ($row){
$arr[]=$row;
$row=mysqli_fetch_assoc($query);
}
while ($row=mysqli_fetch_assoc($query)){
$arr[]=$row;
}
$conenction = new mysqli('127.0.0.1', 'root', '12345678', 'stus');
if ($conenction->connect_error){
die("连接失败");
}
echo "连接成功";
$str="insert into users values (null,'$username','$gender','$birthday',null)";
if ($conenction->query($str)===TRUE){
echo "插入数据成功";
header('Location:userlist.php');
}else{
echo $conenction->error;
}
$conenction->close();
mysqli_free_result($query);
mysqli_close($connection);
mysqli_set_charset($connection,'utf8');
从响应报文的响应头里获取,从请求报文的请求头发出去
如果只传两个参数,不传第三个参数(cookie的过期时间),
默认cookie的过期时间是会话级别(浏览器的打开到关闭,关闭可浏览器就自动删除)
cookie取出来的数据都是字符串类型
setcookie('name','hcy');
setcookie('name');//直传键不传值,删除cookie,过期
toast($_COOKIE);//返回的是关联数组
//设置cookie 一天后到期
setcookie('name','hcy',time()+1*24*60*60);
//path用于设置cookie的作用范围
setcookie('name','hcy',time()+1*24*60*60,'/');
cookie的问题
session_start();//给当前用户找属于他的箱子,session_id 通过cookie的方式存到浏览器(客户端)
session是有类型的,取出来的数据不需要强制转换
$_SESSION['name']='hcy2019';
//取消session
unset($_SESSION['name']);
//获取session
vardump($_SESSION);