View Full Version : PHP Help, quite pathetic really
Zash
June 20th, 2002, 14:06
i dont know y this doesnt work coz i had it working on my old site fine.
wen u login 2 my site it creates a cookie
-----------------------------------------------------------------
setcookie ("mysite_username", $username,time()+3600*24*365);
-----------------------------------------------------------------
which should work fine
but wen i try 2 display this cookie i use either of these pieces of coding & it would display it
-----------------------------------------------------------------
echo "$mysite_username";
-----------------------------------------------------------------
$user = $HTTP_COOKIE_VARS[mysite_username];
echo = $user
-----------------------------------------------------------------
it just wont display ne thing & i aint a clue y but it worked on my old site
ne suggestions?
dawizman
June 20th, 2002, 15:05
it may have something to do with the server if you moved to a new one.
GregT
June 20th, 2002, 15:11
are u certain that its exaclty the same, u could have spaces in it and it could have messed it up, and are ur sure its even setting the cookie that might be were the problem is
Zash
June 20th, 2002, 15:43
thats wot i think. i dont think it is actually setting the cookie coz i cant find it on my computer ne where
ne 1 got a suggestion 2 y it isnt setting it?
bigperm
June 20th, 2002, 16:05
Wow. Your l337 spelling skill don't make me want to help you at all.
English NE1?
cheatpark
June 20th, 2002, 16:27
Try:
<?
$usercookie = $_COOKIE['mysite_username'];
echo "$usercookie";
?>
Edit: If you are having problems setting the cookie then you may wish to set the cookie path as well:
<?
setcookie("mysite_username", "$username", time()+(3600*24*365), "/");
?>
Zash
June 21st, 2002, 02:23
that still doesnt work
:frown2:
biggulp
June 21st, 2002, 04:31
is the $username variable set?
Dusty
June 21st, 2002, 22:59
Cookies are sent in the header, which PHP sends automatically whenever you print or echo something. So that means anytime you call setcookie() after you've printed something out, it won't work. I'd suggest you make sure nothing is printed before you set the cookie and that nothing comes before the opening of your <?php ... ?> tag (this includes no spaces or even line breaks).
Another thing I'd check is to see if you've blocked cookies from the site you're trying this on in your browser. I'd have to check for IE and Opera, but in Mozilla it's:
Edit > Preferences > Privacy & Security > Cookies > click the "Manage Stored Cookies" button, click the "Cookie Sites" tab, if you see your URL and its status is "site cannot set cookies" select it and click the "Remove Site" button.
If all else fails you can ditch setcookie() altogether and just set your cookies manually with header().
ProQ
June 22nd, 2002, 01:48
you should delete ur cookies from the temp folder and put the time a lil less while your still testing... about 2 hours. now, i also think your having a problem with setting the cookie. I remember having a problem setting cookies... it worked at first than for no reason, it just didn't. Now, don't take my word for it because I don't remember, but i think the fix was to put the expiration in quotes ie. "time()+3600". I don't know why that makes a difference, but my script started setting cookies again once i did that.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.