Page 1 of 1

Create a cookie

Posted: Mon Oct 09, 2006 12:49 am
by SidewinderX
is it possable for me to accomplish something like this?

Code: Select all

echo "<a href='http://www.google.com' onclick='".setcookie('clicked', "TRUE", time()+99999)."'>TEST</a>";
obviousally that dosnt work, but is it possable to, when a user clicks on the link, it create a cookie? if so how?

Posted: Mon Oct 09, 2006 12:53 am
by s.dot
Yes.

link

Code: Select all

<a href="http://www.mysite.com/redirect.php?site=http://www.google.com">goooooooooogle</a>
redirect.php

Code: Select all

<?php
if(!empty($_GET['site']))
{
   setcookie('clicked', $_GET['site'], time()+9999);
   header('Location: ' . $_GET['site']);
}
?>
Something like that...