cookies for all OSs
Posted: Thu Jun 12, 2003 12:06 pm
I have cookies working great in IE. But for Netscape, Opera and several browsers in Linux it are not working.
Here is a simple one I have for auto login.
First we set the cookie when they first login
Then I have a check to see if they have a cookie when they come back.
Now I know there are other ways of doing certain routines but this is how I use it. And it works great on IE but not the others.
Here is a simple one I have for auto login.
First we set the cookie when they first login
Code: Select all
<?php
setcookie("valid_user","$valid_user",604800,"/","www.mydomain.com");
setcookie("email","$email",604800,"/","www.mydomain.com");
setcookie("check","valid_user",604800,"/","www.mydomain.com");
?>Code: Select all
<?php
if (empty($_SESSION['valid_user']))
{
if (isset($_COOKIE["check"]))
{
mysql_connect($DBhost,$DBuser,$DBpass) or
die("Unable to connect to database");
@mysql_select_db("$DBname") or die("Unable to select
database");
$sqlquery = "SELECT * From $table where user='".$_COOKIE["valid_user"]."' and email='".$_COOKIE["email"]."'";
$result=mysql_query($sqlquery);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$valid_user=mysql_result($result,$i,'user');
$valid_user=htmlspecialchars($valid_user);
$email=mysql_result($result,$i,'email');
++$i;
}
session_register("valid_user", "email");
// update cookie for time expiration
ob_start();
setcookie("valid_user","$valid_user",604800,"/","www.mydomain.com");
setcookie("email","$email",604800,"/","www.mydomain.com");
setcookie("check","valid_user",604800,"/","www.mydomain.com");
ob_end_flush();
?><meta http-equiv="refresh" content="0"><?
}
else
{
// TestCookie does NOT exist do nothing
}
}
?>