Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2010
    Location
    Australia
    Posts
    93
    Thanks
    38
    Thanked 0 Times in 0 Posts

    destroy cookie in logout

    Hi,
    I have a small login from with the basic username & password field. The values are then passed to a php page which redirects to the main login page, if the login was successful then a cookies value is set. Now i want to have a logout that will destroy my cookie once clicked, please find my code below:

    Code:
    		if (isset($_COOKIE["user"])){
    		
      echo "<tr>";
      echo "<td>Logged in As:</td>";
    
      echo "</tr>";
      echo "<tr>";
        echo "<td>".$_SESSION['username'] . ";</td>";
      echo "</tr>";
    //Here i want a logout button that when clicked should destroy my cookie.
     echo "</tr>

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Set the cookie with a date a few weeks or months in the past to ditch it.

  • #3
    New Coder
    Join Date
    Mar 2010
    Location
    Australia
    Posts
    93
    Thanks
    38
    Thanked 0 Times in 0 Posts
    Thanks Matt, but how can I trigger the destroy session by a button?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Add the required coded to unset session and change cookie's time in a page, say logout.php and then add a link to this page like
    Code:
    <a href="logout.php">Logout</a>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •