mIRC Homepage
Posted By: da_hype php - setcookie() - 19/07/05 01:12 AM
why won't this work??

Code:
$cookie = $filename;
                if (!isset($_COOKIE['$cookie']))
                {
                        setcookie("$cookie",1,time()+600); //expire after 10 mins
                 }
                else { echo "cookie is set"; }
Posted By: coolspot Re: php - setcookie() - 19/07/05 02:55 AM
I would assume its because you have either ', and "'s around the word $cookie. If I recall correctly $variables dont need to be enscupulated by quotes of somekind when referring to them. Try removing them and see what happens.
Posted By: argv0 Re: php - setcookie() - 19/07/05 05:07 PM
While coolspot mentioned "$cookie" is your problem... it is not. Actually, the problem is the one before it, where you use '$cookie'.

There is no problem with using double quotes around text, though in a function (and if the variable is the only value), it is not necessary to put quotes on the cookie. Same goes for an array element. "$cookie" is perfectly legal in php.

However, single quotes are not treated the same as double quotes-- ie. the data inside the quotes does not get evaluated for variables. You'll have to change the $_COOKIE['$cookie'] to double quotes, or take out the quotes altogether


... Also make sure you're setting the cookie BEFORE the headers are sent, which means before any data is sent-- or it won't work. But PHP should give you an error for that.
© mIRC Discussion Forums