Create a cookie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Create a cookie

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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...
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply