This is a discussion on cookies under php 4.06 within the PHP General forums, part of the PHP Programming Forums category; okay, i know this is stupid, and i'm gonna kick myself when someone points out the obvious... i've ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
okay, i know this is stupid, and i'm gonna kick myself when someone points
out the obvious... i've just put a site online, and found the server's running an older version of php (4.06). it's virtual hosting, so i have no control over this... also can't tell you what OS it's running, but it is windows based... the code works locally, although i had to change all $_COOKIE to $HTTP_COOKIE_VARS, same with $_POST, $_SERVER, etc. etc. i've had a quick look through the archives, and googled, but can't find much help around for older installs of php. my code, like i said, the functionality works, but it's just plain not sending the cookie, my little print statements show up and all, but i get no error, and i also get no cookie. <? $error=2; require_once("../inc/db.inc.php"); db_connect('babc'); if(isset($HTTP_GET_VARS['logout'])) { setcookie("UserName", "", time()-(60*60*24)); setcookie("Password", "", time()-(60*60*24)); print "logout"; $error=2; }elseif(isset($HTTP_POST_VARS['login'])){ $SQL = "..."; $res = mysql_query($SQL) or die( mysql_errno." query error" ); $numRows = mysql_num_rows($res); if($numRows==1) { extract(mysql_fetch_array($res)); setcookie("UserName", $HTTP_POST_VARS['UserName'], time()+(60*10), "/", $HTTP_SERVER_VARS['SERVER_NAME']); setcookie("Password", $password, time()+(60*10), "/", $HTTP_SERVER_VARS['SERVER_NAME']); print "login - set cookie"; $error=0; }else{ $error=1; } }elseif (isset($HTTP_COOKIE_VARS ['UserName']) && isset($HTTP_COOKIE_VARS ['Password'])){ $SQL = "..."; $res = mysql_query($SQL) or die( mysql_errno." query error" ); $numRows = mysql_num_rows($res); if($numRows==1) { extract(mysql_fetch_array($res)); setcookie("UserName", $HTTP_COOKIE_VARS['UserName'], time()+(60*10), "/", $HTTP_SERVER_VARS['SERVER_NAME']); setcookie("Password", $password, time()+(60*10), "/", $HTTP_SERVER_VARS['SERVER_NAME']); print "already logged in"; $error=0; }else{ $error=1; setcookie("UserName", "", time()-(60*60*24)); setcookie("Password", "", time()-(60*60*24)); print "problem with login, logout"; } } ?> |
|
|||
|
> setcookie("UserName", $HTTP_POST_VARS['UserName'], time()+(60*10), "/", > $HTTP_SERVER_VARS['SERVER_NAME']); > setcookie("Password", $password, time()+(60*10), "/", > $HTTP_SERVER_VARS['SERVER_NAME']); > print "login - set cookie"; sorry for kinda answering my own post... but anyway... setcookie("UserName", $HTTP_POST_VARS['UserName']); setcookie("Password", $password); solves my problem, although means i can't have a time limit on my cookies i guess... but can set a time limit with another cookie... |
|
|||
|
> sorry for kinda answering my own post... but anyway...
Or you could use header().. http://wp.netscape.com/newsref/std/cookie_spec.html |
|
|||
|
> > setcookie("UserName", $HTTP_POST_VARS['UserName'],
> time()+(60*10), "/", > > $HTTP_SERVER_VARS['SERVER_NAME']); > > setcookie("Password", $password, time()+(60*10), "/", > > $HTTP_SERVER_VARS['SERVER_NAME']); > > print "login - set cookie"; > > > sorry for kinda answering my own post... but anyway... > > setcookie("UserName", $HTTP_POST_VARS['UserName']); > setcookie("Password", $password); > > solves my problem, although means i can't have a time limit on my > cookies i > guess... but can set a time limit with another cookie... 1.) I would not store the user's password in a cookie. 2.) As far as I know, set_cookie() has worked the same since PHP3, so your problem is something else, not the PHP version. Are you sure $HTTP_SERVER_VARS['SERVER_NAME'] is the same as what's in the location bar in your browser. If the server name is set up as www.domain.com but the user is just at http://domain.com the cookie won't set. |