session unset not working properly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joeRaven
Forum Newbie
Posts: 2
Joined: Thu Aug 26, 2004 2:01 am

session unset not working properly

Post by joeRaven »

I have a system where a report is created in 4 steps.

page 1 stablishes some session vars, page 2 some more and so on..
page 4 commits data to database and unsets all report-related session vars like so

Code: Select all

unset($_SESSION['report_var_1']);
unset($_SESSION['report_var_2']);
etc, etc

The reason for having session vars is so that users can navigate back and forth between pages without having them to re-enter all data.

The thing is, after users get to page 4 and unset the vars, when they come back to page 1 to do ANOTHER different report, the session data is still there

in my report pages I am doing somthing like this:

Code: Select all

// report number generator routine

if (!(isset($_SESSION['RID_in'])))
    {
      $sql = "SELECT * from tblreport SORT BY RID DESC;";
      $row = one_query($sql);
      $_SESSION['RID_in'] = $row['RID'] + rand(0,50) + 1;
    }

echo "Creating report ".$_SESSION['RID_in'];
(one_query is my function for getting one row from db)

This should create a number larger than the largest report number in db. This works fine first time in session, but when generating report after unsetting the sessions in page 4, the generated ID from the first report is still my number for the second report.

Any help or rants are much appreciated
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

Sometimes it is easier and more effective (it works all the time :P) to clear the variable value by setting it with null:

Code: Select all

$_SESSION['report_var_1'] = null;
Post Reply