简体   繁体   中英

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). Is this possible to do in PHP? I'm not sure how to load a cookie from a URL.

Thanks in advance!

Hmm...I'm not sure what you're saying, but cookies don't have anything to do with the URL. Cookies are sent as part of the request, but not part of the URL. Check out this explanation at W3 Schools . To access a cookie in PHP you simply use

$_COOKIE['cookiename'];

If you need to access something from the URL, you'd use

$_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.

<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:

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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