...

View Full Version : cookie help



esthera
03-27-2007, 07:21 PM
I have the following

$username="test";
$username="pass";
setcookie("username", $username, time()+3600);
setcookie("password", $password, time()+3600);



echo "<br>username:".$_COOKIE["username"];
echo "<br>password:".$_COOKIE["password"];



echo "Thank You. Your username is:".$username." <br>Your Password is:".$password;


for some reason the cookies are not saving -- what am i doing wrong?

Nightfire
03-27-2007, 07:30 PM
Are both not showing?

You've named the password variable wrong on line 2
$password="pass";

esthera
03-27-2007, 07:46 PM
no that was just a copy and paste error

it is not showing any of the set cookies

Nightfire
03-27-2007, 07:53 PM
Are you setting them before anything is outputted to the browser? Any errors or notices showing?

What does

print_r($_COOKIE);

return?

CFMaBiSmAd
03-27-2007, 08:39 PM
Are the following two echo statements on the same page as the setcookie() statements?

echo "<br>username:".$_COOKIE["username"];
echo "<br>password:".$_COOKIE["password"];If so, $_COOKIE[...] values are not set until the browser sends the cookies back to the web server. This won't happen until the page is refreshed or you browse to a different page.

rafiki
03-27-2007, 08:47 PM
you can simply refresh the page as soon as the cookies have been set by adding

header("Location:http://www.yoursite.com/yourpage.php");
//this will reload the page and echo the cookies that were send :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum