0

I have worked on a little script which can be used to set cookies if you know the location. For example, this code below:

$(window).load(function () {
    $('body').append('<iframe src="http://mydomain.com/setcookie?data=abc123" width="1" height="1" frameborder="0"></iframe>');
}); //sets cookie from desired location, you need its exact id/location.

Does anybody know any good method for taking a created cookie and then applying it to all visitors which visits (using this script), but not knowing the location?

I have thought of extracting the created cookie and then taking the information and creating my own php cookie, is this possible? tell me if I'm being unclear or something..

4

1 回答 1

2

尝试 Jquery Cookie 插件:https ://github.com/carhartl/jquery-cookie它将帮助您在客户端创建 cookie,然后您可以使用标准 PHP 在服务器端读取这些 cookie。

[编辑]

您可以尝试将执行脚本的 URL 发送到服务器:

'<iframe src="http://mydomain.com/setcookie?data=abc123&location=' + 
 window.location.host + '"...

它应该可以让你找到它来自哪里,但它并不安全,因为如果我知道一些编码,我只需要找到一个受信任的主机并对其进行更改,window.location.host你应该最好检查服务器端的请求($ _SERVER['HTTP_REFERER'])。

于 2013-05-15T13:35:10.977 回答