mIRC Home    About    Download    Register    News    Help

Print Thread
#125516 19/07/05 01:12 AM
Joined: Feb 2004
Posts: 119
D
da_hype Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Feb 2004
Posts: 119
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"; }

#125517 19/07/05 02:55 AM
Joined: Mar 2003
Posts: 50
C
Babel fish
Offline
Babel fish
C
Joined: Mar 2003
Posts: 50
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.

#125518 19/07/05 05:07 PM
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
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.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"

Link Copied to Clipboard