forked from JMWpower/xiaojiejie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.php
41 lines (39 loc) · 1.23 KB
/
post.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
ini_set("error_reporting","E_ALL & ~E_NOTICE");
$username=$_POST["userid"];
$url=$_POST["datastr"];
$filename='./user/'.$username.'.json';
if ($username!="" and $url!="") {
if(file_exists($filename)){
$json_string = file_get_contents($filename);
$data = json_decode($json_string, true);
$pd="Y";
$Count = count($data['url']);
for ($i=0; $i < $Count; $i++) {
$urls = $data['url'][$i]['url'];
if ($url==$urls) {
$pd="N";//数据已存在
}
}
if ($pd=="Y") {
$data['url'][$i]['url']=$url;
$json = json_encode($data);
file_put_contents($filename, $json);
}
$datas['status']="YES";
$datas['message']="添加收藏成功!";
echo json_encode($datas);
}else{
$data['url'][0]['url']=$url;
$json = json_encode($data);
file_put_contents($filename, $json);
$datas['status']="YES";
$datas['message']="添加收藏成功!";
echo json_encode($datas);
}
}else{
$datas['status']="NO";
$datas['message']="未知的错误,添加收藏失败!";
echo json_encode($datas);
}
?>