Problem with cookies

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swethak
    New Member
    • May 2008
    • 118

    Problem with cookies

    Hi,


    my requirement is to "when we close the browser it automatically signout the account". For that i am using the cookies and set the cookie expiration time as '0' . But it didn't work in mozilla and it works fine in IE.
    Here is code i am using

    Code:
    <?
    if(isset($_POST['submit'])){
    $email=$_POST['email'];
    $password=$_POST['password'];
    setcookie("TestCookies", $email,0);
    setcookie("TestCookies1", $password,0);
    echo $_COOKIE['TestCookies'];
    }
    ?>
    <html>
    <body>
    <?
    if(isset($_COOKIE['TestCookies'])){
    echo "Welcome to ".$_COOKIE['TestCookies'];
    echo "<br>";
    echo "<a href=logout.php>Logout</a>";
    }
    else{
    ?>
    <form name="form1" method="post" action="">
    Email: <input type="text" name="email" value="" /><br />
    Password: <input type="text" name="password" value=""  /><br />
    <input type="submit" name="submit" value="Submit" />
    </form>
    <?
    }
    ?>
    </body>
    </html>
    logout.php

    Code:
    <?
    setcookie('TestCookies',"");
    setcookie('TestCookies1',"");
    header('Location:login.php');
    ?>
    Any body please give the solution how can i resolve my problem.
    please help me.Its urgent.
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    SESSIONS are alive until the browser is closed, or before (depending on the lifetime setting.

    Comment

    • Nert
      New Member
      • Nov 2006
      • 64

      #3
      Yeah, markus is right, try using SESSION, in PHP settings by default the session is set to end when the browser is closed.

      check this out.

      Comment

      Working...