Jump to content

[SOLVED] Clearing Session Variables for Good!


oceans

Recommended Posts

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();

 

 

......

"

Link to comment
Share on other sites

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 ;D

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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 ;D

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.