简体   繁体   English

从PHP中的URL加载cookie

[英]Load cookie from URL in PHP

I have a page written in PHP and I've been asked to load a counter cookie and given a url (HTTP://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?cn=as&ActivityID=XXXXXX&ns=1). 我有一个用PHP编写的页面,并且被要求加载计数器cookie并指定一个URL(HTTP://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?cn=as&ActivityID=XXXXXX&ns=1)。 Is this possible to do in PHP? 这可以在PHP中完成吗? I'm not sure how to load a cookie from a URL. 我不确定如何从URL加载Cookie。

Thanks in advance! 提前致谢!

Hmm...I'm not sure what you're saying, but cookies don't have anything to do with the URL. 嗯...我不确定您在说什么,但cookie与URL没有任何关系。 Cookies are sent as part of the request, but not part of the URL. Cookie是作为请求的一部分发送的,而不是URL的一部分。 Check out this explanation at W3 Schools . 在W3 Schools上查看此说明 To access a cookie in PHP you simply use 要使用PHP访问Cookie,您只需使用

$_COOKIE['cookiename'];

If you need to access something from the URL, you'd use 如果您需要从URL访问某些内容,则可以使用

$_GET['variable_name'];

I think what you're talking about is a random number that is used to associate advertisement impressions to advertisement clicks. 我认为您在说的是一个随机数,该随机数用于将广告展示次数与广告点击次数相关联。

Here's a typical ad that uses that format. 这是使用该格式的典型广告。

<a href="http://adnetwork.tld/click?ad=1234567&session=98765">
<img src="http://adnetwork.tld/view?ad=1234567&session=98765" />
</a>

Here's a typical way of generating that ad on the client side with Javascript. 这是使用Javascript在客户端生成广告的一种典型方法。

<script language="javascript" type="text/javascript">
var random = Math.floor(Math.random() * 100000000);
document.write('<a href="http://adnetwork.tld/click?ad=1234567&session=' + random + '">');
document.write('<img src="http://adnetwork.tld/view?ad=1234567&session=' + random + '" />');
document.write('</a>');
</script>

I'm sorry if that wasn't what you were looking for but that's what it seems like going off of your question. 很抱歉,如果这不是您想要的,那似乎就是您的问题了。

To generate a cookie from the variable: 要从变量生成Cookie:

$content = $_GET['ActivityID'];
$expire = time()+60*60*24*30;
setcookie("AID", $content, $expire);

Not sure if this is what you were after, but this will set a cookie for the user called "AID", with the value of the ActivityID. 不知道这是不是您想要的,但这会为用户设置一个名为“ AID”的cookie,并带有ActivityID的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM