Page 1 of 1

Using strings in cookies?

Posted: Thu Aug 05, 2010 6:46 am
by dominod
Hi

I am having troubles using a string in a cookie..

This doesnt work:

Code: Select all

setcookie("background", "$image_name", $expire, "/", ".gedoo.com");
Neither does this:

Code: Select all

setcookie("background", "" . $image_name . "", $expire, "/", ".gedoo.com");
If I write something before $image_name like:

Code: Select all

setcookie("background", "hello" . $image_name . "", $expire, "/", ".gedoo.com");
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:

Code: Select all

echo "File Uploaded Successfully!<br><img src='images/$image_name'>";
Anyone have any idea on what I am doing wrong?

Re: Using strings in cookies?

Posted: Thu Aug 05, 2010 6:54 am
by superdezign
What about it isn't working...?

Why don't you try only providing the first 3 arguments to setcookie and seeing what you end up with?

Re: Using strings in cookies?

Posted: Thu Aug 05, 2010 7:18 am
by requinix
If it works on the same page then it was defined somewhere. Not necessarily before you call setcookie().

Re: Using strings in cookies?

Posted: Thu Aug 05, 2010 7:28 am
by dominod
Yes it is defined before setcookie like:

Code: Select all

 	echo "File Uploaded Successfully!<br><img src='images/$image_name'>";
 }


$expire=time()+60*60*24*3000;
setcookie("background", "$image_name", $expire, "/", ".gedoo.com");

Re: Using strings in cookies?

Posted: Thu Aug 05, 2010 9:55 am
by dominod
I figured it out !

I was sending output before I was calling setcookie ... :p

Im a newbie BTW