PDA

View Full Version : PHP cookie script for IE failing?



Demonicman
01-24-2009, 08:32 PM
if(!$_COOKIE['passer'] || $_COOKIE['passer']!='blo'){
if(!$_POST['submit']){
echo "<form action=ROMDB.php method=post><input class='button' name='pass' type='password'><input class='button' type='submit' name='submit' value='Submit Password'></form>";
exit;
}else{
if($_POST['pass']!='blo'){
echo "Incorrect pass! <a href='ROMDB.php'>Go back</a>";
exit;
}else{
setcookie ("passer", "", time() - 3600);
setcookie("passer","blo",time()+60*60*24*30,"/",0);

}
}

why would this not work in internet explorer?? its not saving the cookie

first i expire the cookie then remake it...

it will submit first and you can see the rest of the page, but if you hit refresh or navigate back its like you never inserted a password in the first place...

mada9369
01-24-2009, 10:21 PM
use $_SESSION['id'];

=D.

i believe that is the same thing, just much safer.

Demonicman
01-24-2009, 11:25 PM
thanks, after reading a tutorial i added session variables and its working perfect! unfortunatly i dont know how long sessions in php last, they dont mention it... any idea?

mada9369
01-25-2009, 06:57 PM
I'm not sure how long they last.

But if you just add


<?php
session_start();
?>

above everything else on your page, they will keep going.

Nile
01-25-2009, 07:30 PM
Sessions last until the browser is closed.
Try this:


<?php
if (!$_COOKIE['passer'] || $_COOKIE['passer'] != 'blo') {
if (!$_POST['submit']) {
echo "<form action=ROMDB.php method=post><input class='button' name='pass' type='password'><input class='button' type='submit' name='submit' value='Submit Password'></form>";
exit;
} else {
if ($_POST['pass'] != 'blo') {
echo "Incorrect pass! <a href='ROMDB.php'>Go back</a>";
exit;
} else {
setcookie("passer", "blo", time() + 60 * 60 * 24 * 30, "/", 0);
}
}
?>