Hi I am having troubles using a string in a cookie.. This doesnt work: setcookie("background", "$image_name", $expire, "/", ".gedoo.com"); PHP: Neither does this: setcookie("background", "" . $image_name . "", $expire, "/", ".gedoo.com"); PHP: If I write something before $image_name like: setcookie("background", "hello" . $image_name . "", $expire, "/", ".gedoo.com"); PHP: It will save "hello" in the cookie.. So in other words, $image_name doesnt look like it is defined.. But the funny thing is that this works on the same page: echo "File Uploaded Successfully!<br><img src='images/$image_name'>"; PHP: Anyone have any idea on what I am doing wrong?
You may want to check to see whether or not the variable $image_name is actually populated with data at the time you're attempting to set the cookie.
Yes it is .. Actually it is echoed right before like: echo "File Uploaded Successfully!<br><img src='images/$image_name'>"; } $expire=time()+60*60*24*3000; setcookie("background", "$image_name", $expire, "/", ".gedoo.com"); PHP:
There's a closing bracket right after it. Could that perhaps be a conditional statement that isn't being met? Is the present HTTP host gedoo.com? Perhaps you could try something simpler: $expire=time()+60*60*24*3000; setcookie("background", $image_name, $expire); print_r( $_COOKIE ); PHP: edit: you'll have to refresh once for the $_COOKIE variable to be populated, since the option to set-cookie is part of the returned HTTP header.
if it's echoed before, that would send the header meaning the cookie can't be set iirc. Set the cookie before you send any text for testing what cookies have been set personally use foreach ($_COOKIE as $v => $a) { echo "$v - $a<br/>"; } PHP:
For tracking sessions always prefer to go for Sessions, not Cookies. It's efficient, secure and fast. However, if you want to store user data permanently, you can't go with sessions.