...

View Full Version : Cookie is not being set!



wallport10
11-10-2006, 01:46 AM
<?
include 'sql.php';

$username=$_POST["username"];
$query = "SELECT * FROM users WHERE username = '$username'";
$result = mysql_query($query, $link) or die("Query Failed!2");
$password=$_POST["password"];
if ($line = mysql_fetch_array($result, MYSQL_ASSOC) ==''){
echo "<html><head><title>Login: Devastation</title></head><center><font color='white'>User $username not found in database!";
}else{
mysql_free_result($result);
$result = mysql_query($query, $link) or die("Query Failed!3");
$row = mysql_fetch_assoc($result);
if ($password == $row["password"]){
$id=$row['id'];
mysql_query("delete from online where id='$id'", $link) or die("Yeah");
mysql_query("insert into online values ('$id', '$tm')", $link) or die("Query Failed!4");
setcookie('Dev', $id, time()+3600);
$herm = $_COOKIE["Dev"];
$type=$row['type'];

print "<iframe name='I1' width='100%' height='90%' src='main.php' align='center' border='0' frameborder='0'>
Your browser does not support inline frames or is currently configured not to display inline frames.
</iframe>";


print "<center><p align='bottom'><font size='1' color='white'><a href='main.php?link=home' target='I1'>Home</a> - <a href='main.php?link=prefs' target='I1'>Preferences</a> - <a href='main.php?link=leave' target='I1'>Leave Form</a> -";if($type=='1'){print "<a href='main.php?link=admin' target='I1'>Admin</a> - ";}print " <a href='main.php?link=logout' target='I1'>Logout</a>";

}else{
Print "<center><font color='white'>Invalid Password, try again!<br>";
}}

mysql_free_result($result);

mysql_close($link);

Its not creating a Cookie from what I see... on my main.php page here is what I have set up...


<?
/*Reset Cookie to prevent loggout*/
$id=$_COOKIE["Dev"];

/* Chech to see if Logged Out */
if ($id == ""){
setcookie ("Dev", "", time()-3600);
print "<html><body><center><h2>YOU ARE LOGGED OUT1</h2></center></body></html>";
exit;
}else{
include 'sql.php';
$result = mysql_query("SELECT id FROM online where id=$id" , $link) or die("Query1 failed");
$row = mysql_fetch_assoc($result);
if ($row["id"]!=$id){
setcookie ("Dev", "", time()-3600);
print "<html><body><center><h2>YOU ARE LOGGED OUT2</h2></center></body></html>";
exit;
mysql_close($link);
}}

I spent about 5 hours last night trying to get this to work... advice would be appreciated!

-Nate

ess
11-10-2006, 10:49 AM
The cookie has not been set...because you're setting in the past.

setcookie ("Dev", "", time()-3600); // here you are saying cookie has expired an hour ago

Basically, when you want to delete a cookie...you set it to a date past today's date...and it would be deleted automatically.

so...change the above statement to the following and it should work for an hour
setcookie ("Dev", "", time()+3600);// cookie is active for an hour

hope that helps.
ess

wallport10
11-12-2006, 12:09 AM
You misread it, the first php page I put on is the page that sets the cookie! The main.php page (2nd php page) sets it negative time when no Variable ID is found, deminishing the cookie. Hence the check to see if the cookie exists! No cookie is being created!

SCwebbie
11-21-2006, 12:40 PM
instead of


setcookie('Dev', $id, time()+3600);try



$host = $_SERVER['HTTP_HOST'];
setcookie('Dev', "$id", time()+3600, "/", "$host");
had the same problem once and this solved it.

wallport10
11-23-2006, 01:23 AM
freaking awsome! That worked perfectly... thank you very much!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum