oceans Posted July 10, 2007 Share Posted July 10, 2007 Dear People, I have a concern pertaining my session variables handling, I am using quite a bit of session variables (properly declared and named). I have grouped a few sets of pages, I want to clear all the session variables (immaterial of which group of pages they belong) when any page group begins. I tried placing session_destroy(); in the beginning of the header, since I post my pages to itself for validation, it DOES NOT work as per my intention. Thus can any one suggest how could I remove the entire content in the session file without caring about the session variables name. Thanks. FYI this is what I did at first few lines in the header " <?php ob_start(); session_start(); session_destroy(); ...... " Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 dear oceans, Its impossible that you cannot destroy the session by using session destroy maybe you are just doing it wrong. maybe after destroying you have still sort of code that set back the value maybe you want to show us how you destroy the code Sincerely yours teng Quote Link to comment Share on other sites More sharing options...
oceans Posted July 10, 2007 Author Share Posted July 10, 2007 Dear Tang84, I am sorry, I misled you, yes "session_destroy();" does its job perfect, but I can't use session variables after that instruction, yes, I will post my code "extract" as my page runs a bit long please give me 1 min... thanks.... Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 hmm have you tried unset() Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 dear oceans, I wonder why you have to use this dear dear dear dear any way try unset($_SESSION['put the index here']); sincerely yours teng Quote Link to comment Share on other sites More sharing options...
oceans Posted July 10, 2007 Author Share Posted July 10, 2007 Friend I was polite, ok I will take you as my friend, address you Teng84. Please take a look at my extract of my typical page, this is a log in page... <?php ob_start(); session_start(); session_destroy(); $_SESSION['0101LogInTo0201Member01']=0; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?PHP $NumberOfTxtBoxes=2; $NumberOfTxtBoxesMustBeFilled=2; //Transfer Data from Screen to Memory if (isset($_POST['Submit'])) { for ($i=1; $i<=$NumberOfTxtBoxes; $i++) { $InputFromScreen[$i]=strip_tags(trim(strtoupper($_POST["Txt".$i]))); } } else { for ($i=1; $i<=$NumberOfTxtBoxes; $i++) { $InputFromScreen[$i]=""; } } ?> <form id="form1" name="form1" method="post" action="0101LogIn.php"> <td class="PHPRunTime"><?PHP //Checking for Unfilled Fields $TxtBoxesNotFullyFilled=0; for ($i=1; $i<=$NumberOfTxtBoxesMustBeFilled; $i++) { if ($InputFromScreen[$i]=="") { $TxtBoxesNotFullyFilled=1; break; } } if ($TxtBoxesNotFullyFilled==1) { echo "All Fields Should be Filled!"; } else { if ($InputFromScreen[2]!=$InputFromDataBase[1]) { //Password Does Not Match echo "Incorrect Email Address or Password!"; } else { //Send Email Address to Next Page $_SESSION['0101LogInTo0201Member01']=$InputFromScreen[1]; header("location: 0201Member.php"); } } ?> </td> </form> </body> </html> PS. As with unset I need to specify all variables individually, I want one shoot all dead! I will never know which group my viewer came from prioer to this page. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 ob_start(); session_start(); if($_SESSION['count']<=0) { session_destroy(); } $_SESSION['count']=1; $_SESSION['0101LogInTo0201Member01']=0; hmm that does make sense or tell me what i have done wrong Quote Link to comment Share on other sites More sharing options...
oceans Posted July 10, 2007 Author Share Posted July 10, 2007 Please give me 1 min, I am thinking and trying... Quote Link to comment Share on other sites More sharing options...
oceans Posted July 10, 2007 Author Share Posted July 10, 2007 No, it is not working, I belive the session file gets removed this way, thus no session data for the next page, also I believe it should be " if($_SESSION['count']==1) " Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 look heres what the code i gave you does when the user get into that page for the 1st time all the session will destroy or erase but if he or she go there for the second etc the session wont be deleted hmm can you give me more xplanation on your objective Quote Link to comment Share on other sites More sharing options...
oceans Posted July 10, 2007 Author Share Posted July 10, 2007 I have 5 groups of pages; In each group, there are few pages; the "next" page requires information from "this" page in the same group. When the user walkes from, say mid of Group 2 to start of Group 1, start page of Group 1 should flush all content of the session file... Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 hmm i guess session destroy is not the sulotion maybe u need the condition isset or empty if(!isset($_SESSION['here'])) { then do some stuff here like the header(location) bring the user to first page or to the last page he or she is welcome or any } does it make sense now Quote Link to comment Share on other sites More sharing options...
oceans Posted July 10, 2007 Author Share Posted July 10, 2007 Teng84, Sounds Sound, give me time, I work out and let you know... Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 may i know what site is that is it a project?? Quote Link to comment Share on other sites More sharing options...
oceans Posted July 10, 2007 Author Share Posted July 10, 2007 What does " isset($_SESSION['here'] " does? It looks for the presence of the variable or the value (here)? So I have to set a value and clear as and when required is it? I am doing in WAMP, testing phase should be publishing soon after ironing out staffs... Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 isset($_SESSION['here']//this asked if this session has been set and i add ! so it the other way around Quote Link to comment Share on other sites More sharing options...
oceans Posted July 10, 2007 Author Share Posted July 10, 2007 Friend, Your method works, killing variable one by one is hard in my case. Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 10, 2007 Share Posted July 10, 2007 dear oceans cool truly yours teng; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.