SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Clear session variable while still in program

    Hi there

    I need to be able to clear all the session variables when the link to my main_menu.php is used - the first thing main_menu needs to do is dump whatever the session variables have.
    I have tried using unset and session_destroy but I'm not getting anywhere.

    I've read a bunch of posts from this forum and nothing has helped yet.

    Session_destroy isn't working because main_menu is also the entry point into the software and if it's the first time into the software the following message appears:
    Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in /var/www/localhost/htdocs/costing/firstpage.php on line 4.

    The code for main_menu is:
    PHP Code:
    <?PHP
    unset ($_SESSION['region']);
    unset (
    $_SESSION['region2']);
    session_start();
    $status_level=$_SESSION['status_level'];
    $_SESSION['status_level']=$status_level;

    ?>

    <html>
    <title>Schedule of Costing (new selection)</title>
    <head>
    <link rel="stylesheet" type="text/css" href="costingstyle.css" />
    </head>
    <body>

    <br>
    <br>
    <p><HEADS>&nbsp &nbsp &nbsp Please select a region</HEADS>
    <br>
    <br>
    <? 
    if ($status_level == 1) { 
    ?>
       <form action=admin_selection.php method=post>
       &nbsp &nbsp &nbsp&nbsp &nbsp &nbsp &nbsp<select name="region">
       <option value="Gauteng">Gauteng</option>
       <option value="Cape">Cape</option>
       <option value="KZN">Natal</option>
       </select>
       <br>
       <br>
       <br>
       &nbsp &nbsp &nbsp&nbsp &nbsp &nbsp &nbsp<input type=submit value="Submit">
       </form>
    <?
    }

    else { 
    ?>
       <form action=selection.php method=post>
       &nbsp &nbsp &nbsp&nbsp &nbsp &nbsp &nbsp<select name="region">
       <option value="Gauteng">Gauteng</option>
       <option value="Cape">Cape</option>
       <option value="KZN">Natal</option>
       </select>
       <br>
       <br>
       <br>
       &nbsp &nbsp &nbsp&nbsp &nbsp &nbsp &nbsp<input type=submit value="Submit">
       </form>
    <?
    }
    ?>


    <br>
    <br>
    <br>
    <LINKS><a href=logout.php><font size=2>Logout</a></LINKS>

    </body>
    </html>

    I would appreciate any advice!

  2. #2
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You cannot unset session variables without starting session. So first start it and then check whether any session variable exist. If that exist then unset it.

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2009
    Location
    South Florida
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try session_destroy();

  4. #4
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    achintya is correct - you have to first start the session. Another way is clear the session is to set it back to an array.
    PHP Code:
    session_start();
    $_SESSION = array(); 
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development


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
  •