Cookie Setting

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
referendo
Forum Newbie
Posts: 2
Joined: Wed Aug 13, 2003 6:12 pm

Cookie Setting

Post by referendo »

i've been trying to create a page that will stamp a cookie and redirect to our home page
cookie name: ezrefer
page name

ie: http://ww.anydomain.com/ezb.php?ezrefer=REFERCODE

REFERCODE is the code i want to stamp for this user depending on where they came from. so REFERCODE will change all the time.

but when i type the following code, no cookie is set because I HAVE TO put a value for $name, correct?

basically i don't want the cookie "ezrefer" to always be a static value.

is this possible?

<?php
$today = date("F j, Y, g:i a");
$name = "";
setcookie("ezrefer-$today",$name,time()+31536000,"/", ".ezboard.com");
$URL="http://www.ezboard.com";
header ("Location: $URL");
?>

thanks in advance...

- Randy -
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

You've got the order mixed up; the syntax for setting a cookie is:

setcookie('name',$value);


So you're setting a cookie named "ezreferer-$today" with the value of "" (absolutely nothing), which (IIRC) deletes the cookie.
referendo
Forum Newbie
Posts: 2
Joined: Wed Aug 13, 2003 6:12 pm

Post by referendo »

would i be able to change the value of "ezrefer-$today" according the url? like if i type this in the url:

http://www.anydomain.com/myphp.php?ezre ... y=ANYVALUE

would i be able to set the ezrefer-$today value to that just by typing that in the url?
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

How about myphp.php?date=ANYVALUE :

Code: Select all

$cookie_value = "PHP rules!";
$today = $_GET['date'];
$cookie_name = "ezreferer-$today";
setcookie($cookie_name,$cookie_value);
Post Reply