How to maintain a session from page to page? I'm getting a problem here when i try to logout, the session is destroy but i still can go inside to that page without login first by using IE Back button or history cache! How can i solve that? Anybody help me please...
Sessions
Collapse
X
-
hello sir ... im a little bit confuse.. what's question exactly? how to maintain a session or how to destroy it? -
-
Originally posted by ronverdonkShow us the code by which you destroy the session.
Ronald :cool:
in my first program
--------------------------------------------------------------------------------------------------------------------
index.php
--------------------------------------------------------------------------------------------------------------------
<?php
session_start() ;
include("dbconn ect.php");
if(isset($_POST['login']))
$username = $_POST['login'];
else
$username = "";
if(!empty($user name))
{
if(isset($_POST['pass']))
$pas =$_POST["pass"];
$qry = <<<STR
select username,passwo rd from users where username='$user name' and password='$pas' ;
STR;
$r=mysql_query( $qry)or die(mysql_error ());
$r1=mysql_fetch _assoc($r);
$rowcount=mysql _num_rows($r);
if($rowcount==1 )
{
$_SESSION['username'] = $r1["username"];
?>
<script language="javas cript">
document.locati on = "viewRecords.ph p";
</script>
<?php
}
else
{
print "invalid user";
}
}
?>
--------------------------------------------------------------------------------------------------------------------
view records.php
--------------------------------------------------------------------------------------------------------------------
<?php
session_start() ;
if(!isset($_SES SION["username"]))
{
die ("ERROR: Unauthorized access!");
}
else
{?>
<?php
function logout()
{
session_destroy ();
}
?>
<td width="150" align="center" valign="middle" background="ima ges/sub_menu.jpg">< span class="right">< a href="index.php " onClick="logout ();">Logout</a></span></td>
<?php
include("dbconn ect.php");
$results = mysql_query("se lect * from insertrecord ");
while($row = mysql_fetch_arr ay($results))
{
echo "<tr>";
echo "<td>" . $row['jobname'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['entrydate'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
}
?>
NOTE:this is my situation when I click on logout button I just called session destroy function.but after clicking on log out button when i select browser's back button Im able to view all the details.
please help me ronald
regards,
ramyaComment
-
Originally posted by exoskeletonhello sir ... im a little bit confuse.. what's question exactly? how to maintain a session or how to destroy it?
in my first program
--------------------------------------------------------------------------------------------------------------------
index.php
--------------------------------------------------------------------------------------------------------------------
<?php
session_start() ;
include("dbconn ect.php");
if(isset($_POST['login']))
$username = $_POST['login'];
else
$username = "";
if(!empty($user name))
{
if(isset($_POST['pass']))
$pas =$_POST["pass"];
$qry = <<<STR
select username,passwo rd from users where username='$user name' and password='$pas' ;
STR;
$r=mysql_query( $qry)or die(mysql_error ());
$r1=mysql_fetch _assoc($r);
$rowcount=mysql _num_rows($r);
if($rowcount==1 )
{
$_SESSION['username'] = $r1["username"];
?>
<script language="javas cript">
document.locati on = "viewRecords.ph p";
</script>
<?php
}
else
{
print "invalid user";
}
}
?>
--------------------------------------------------------------------------------------------------------------------
view records.php
--------------------------------------------------------------------------------------------------------------------
<?php
session_start() ;
if(!isset($_SES SION["username"]))
{
die ("ERROR: Unauthorized access!");
}
else
{?>
<?php
function logout()
{
session_destroy ();
}
?>
<td width="150" align="center" valign="middle" background="ima ges/sub_menu.jpg">< span class="right">< a href="index.php " onClick="logout ();">Logout</a></span></td>
<?php
include("dbconn ect.php");
$results = mysql_query("se lect * from insertrecord ");
while($row = mysql_fetch_arr ay($results))
{
echo "<tr>";
echo "<td>" . $row['jobname'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['entrydate'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
}
?>
NOTE:this is my situation when I click on logout button I just called session destroy function.but after clicking on log out button when i select browser's back button Im able to view all the details.
regards,
ramyaComment
-
You don't really expect me to look at 3 posts of unstructured code displays, do you??
Before you show any code, read the Posting Guidelines at the top of this forum!
Especially the part about enclosing shown code within php or code tags!!
Ronald :cool:Comment
-
Originally posted by Hyperionwhen i try to logout, the session is destroy but i still can go inside to that page without login first by using IE Back button or history cache! How can i solve that?
So now you log out. You call session_destroy (), which will delete all of the session-related information saved on the local server. It does NOT, however, delete the remote cookie. When the user tries to return to your site, and it is asking for a session id, the user is going to return the same session id it had last time. When your server does not see this session (because it has been destroyed locally), it will recreate a new session with the same id. Here's the catch: ANYWHERE ELSE YOU TIED TO THE SESSION ID AND DID NOT CLEAR WILL CONTINUE TO BE TIED. So, if you saved a cart using the session id as a way to track it, the cart will 'resurrect' itself from a destroyed session because you never removed the data.
Your solutions:
1) kill the remote cookie. See setcookie() for this.
2) kill the local session. session_destroy () handles this.
3) remove session-related tracks in your database...eras e the cart, remove any login indicators, etc.Comment
Comment