SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ending PHP Session

    Hi guys,
    I am currently building a shopping cart. I have done all of the logic up to the point where the items bought are summed up and ready to send to the payment gateways. But I have a problem.

    My shopping cart doesnt require that a user log in to shop, it assigns a session to that user at the beginning and passes that session all along the pages till he gets to checkout.

    Now I want to end this user's session as soon as he gets to checkout so that any other buyer who comes in on that browser after him will meet an empty shopping cart. I have not been able to achieve that either with session_destroy() or unset_session().

    Please kindly help me. I appreciate

  2. #2
    SitePoint Member
    Join Date
    Aug 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    unset($_SESSION['cart']); after processing the order

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,833
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    I use $_SESSION and try to emulate a new user with no $_SESSION set.

    I have tested the Global $_SESSION array variable and clear the contents like this:


    PHP Code:

    <?php 
     
    #before clearing
     
    echo '<pre>';
       
    print_r$_SESSION );    
     echo 
    '</pre>';

     
    $_SESSION = array();

     
    #after clearing
     
    echo '<pre>';
       
    print_r$_SESSION );    
     echo 
    '</pre>';
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,161
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    I don't remember where I found this ages ago, the documentation I think, anyway it might help even if I can't decipher my own notes


    1. Destroying a session with $_SESSION

    <?php
    // Initialize the session.
    // If you are using session_name("something"), don't forget it now!
    session_start();

    // Unset all of the session variables.
    $_SESSION = array();

    // If it's desired to kill the session, also delete the session cookie.
    // Note: This will destroy the session, and not just the session data!
    if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time()-42000, '/');
    }

    // Finally, destroy the session.
    session_destroy();
    ?>
    unset ($_SESSION['varname']);.


Tags for this Thread

Bookmarks

Posting Permissions

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