cookies under php 4.06

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-04-2003
Chris Kranz
 
Posts: n/a
Default cookies under php 4.06

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";
}
}
?>

Reply With Quote
  #2 (permalink)  
Old 09-04-2003
Chris Kranz
 
Posts: n/a
Default Re: cookies under php 4.06


> 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...
Reply With Quote
  #3 (permalink)  
Old 09-04-2003
Comex
 
Posts: n/a
Default Re: cookies under php 4.06

> sorry for kinda answering my own post... but anyway...
Or you could use header()..
http://wp.netscape.com/newsref/std/cookie_spec.html
Reply With Quote
  #4 (permalink)  
Old 09-04-2003
Jennifer Goodie
 
Posts: n/a
Default RE: [PHP] Re: cookies under php 4.06

> > 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.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:17 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0