跨域2

发布于 2015-09-15 / 前端 / 0条评论 / 3,310浏览

hello all

新的一天来了,继续上次的未完待续,感觉年纪大了。熬夜早起不午睡…已是过去…

上次说到如何确认是谁访问的网页,该如何判断。或许有同学会说:IP、User-Agent、Cookie等等;Good 完全正确。

既然知道利用这些就能判断是谁访问网页的,我们就可以定位他当前的访问的页面,将先上传到服务器,然后地址返回到他/她的地址栏上了。

不多说了,直接上马
上传URL(http://wordpress.denghb.com/access/upload)

// 忽略mysql连接...
// 防止SQL注入
$url = check_input($dbc,$_GET["url"]);
// 先把这个机器以前的访问逻辑删除
$sql = "update access set deleted = 1,updated_time = now() where user_agent = '$userAgent' and ip = '$ip';";
$result = mysqli_query($dbc,$sql);
// 添加数据
$sql = "insert into access(url,user_agent,ip) values ('$url','$userAgent','$ip');";
//echo $sql.'<br/>';
$result = mysqli_query($dbc,$sql);
if (!$result)
{
  echo "try {console.log('link upload error :(')} catch (e) {}";
}
mysqli_close($dbc);

查询URL (http://wordpress.denghb.com/access/get)

// 按UA和IP查询
$sql = "select url from access where user_agent = '$userAgent' and ip = '$ip' and deleted = 0 limit 0,1";
//echo $sql;
$result = mysqli_query($dbc,$sql);
//echo $result;
$row = mysqli_fetch_array($result);
// 不为空才返回
if (isset($row[url])){
  echo 'showUrl("'.$row[0].'")';
}	
mysqli_close($dbc);

以上就是服务端的实现,简单吧。(呵呵,不要说我收录你们的UA和IP…我就是收录了…_
这个是有些问题的,比如说在同一个公司或网吧等,浏览器都是一样的这个就没有效果了

其实还可一在刚访问的时候就随机生成一个code(时间戳也行),然后通过iframe的src传递到wordpress,在wordpress中存入cookie里面,下次就用这个code当成唯一标记的参数来标记当前用户;这个我就不实现了(因为已经够了)…有兴趣的可以去试试…

以后每一两天就更新一次。

Note:
防SQL注入

评论
站长统计