473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Sessions

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...
Feb 23 '07 #1
9 1394
exoskeleton
104 100+
hello sir ... im a little bit confuse.. what's question exactly? how to maintain a session or how to destroy it?
Feb 23 '07 #2
ronverdonk
4,258 Expert 4TB
Show us the code by which you destroy the session.

Ronald :cool:
Feb 23 '07 #3
amrhi
22
please write your code.
But i think you forget to include session code in your page .so you can come again without log in.
for example try to write:include"check_session.php"; in your page.
Feb 23 '07 #4
Show us the code by which you destroy the session.

Ronald :cool:
Hello Ronald Thanks for ur reply,
in my first program
--------------------------------------------------------------------------------------------------------------------
index.php

--------------------------------------------------------------------------------------------------------------------
<?php

session_start();

include("dbconnect.php");

if(isset($_POST['login']))

$username = $_POST['login'];

else

$username = "";



if(!empty($username))

{

if(isset($_POST['pass']))

$pas =$_POST["pass"];



$qry = <<<STR

select username,password from users where username='$username' 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="javascript">

document.location = "viewRecords.php";

</script>

<?php

}

else

{

print "invalid user";

}



}

?>


--------------------------------------------------------------------------------------------------------------------
view records.php
--------------------------------------------------------------------------------------------------------------------
<?php

session_start();

if(!isset($_SESSION["username"]))

{

die ("ERROR: Unauthorized access!");

}

else

{?>

<?php

function logout()

{

session_destroy();

}

?>



<td width="150" align="center" valign="middle" background="images/sub_menu.jpg"><span class="right"><a href="index.php" onClick="logout();">Logout</a></span></td>



<?php

include("dbconnect.php");

$results = mysql_query("select * from insertrecord ");

while($row = mysql_fetch_array($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,
ramya
Feb 28 '07 #5
hello sir ... im a little bit confuse.. what's question exactly? how to maintain a session or how to destroy it?
when i use this code Im able to enter into the website even though I logout,when I click on browsers back button
in my first program
--------------------------------------------------------------------------------------------------------------------
index.php

--------------------------------------------------------------------------------------------------------------------
<?php

session_start();

include("dbconnect.php");

if(isset($_POST['login']))

$username = $_POST['login'];

else

$username = "";



if(!empty($username))

{

if(isset($_POST['pass']))

$pas =$_POST["pass"];



$qry = <<<STR

select username,password from users where username='$username' 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="javascript">

document.location = "viewRecords.php";

</script>

<?php

}

else

{

print "invalid user";

}



}

?>


--------------------------------------------------------------------------------------------------------------------
view records.php
--------------------------------------------------------------------------------------------------------------------
<?php

session_start();

if(!isset($_SESSION["username"]))

{

die ("ERROR: Unauthorized access!");

}

else

{?>

<?php

function logout()

{

session_destroy();

}

?>



<td width="150" align="center" valign="middle" background="images/sub_menu.jpg"><span class="right"><a href="index.php" onClick="logout();">Logout</a></span></td>



<?php

include("dbconnect.php");

$results = mysql_query("select * from insertrecord ");

while($row = mysql_fetch_array($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,
ramya
Feb 28 '07 #6
ronverdonk
4,258 Expert 4TB
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:
Feb 28 '07 #7
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?
It sounds like your problem is related to the cookie. When a session is created, the session information is stored locally on the server, and a session ID is sent to the remote system by way of a session cookie. It is usually called "PHPSESSID" or some other obvious name. The remote system stores this as the 'key' to their session on the server.

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...erase the cart, remove any login indicators, etc.
Feb 28 '07 #8
thanq for u reply sir.
can u please give me an example of destroying a remote cookie .
Mar 26 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: The Plankmeister | last post by:
Hi... I'm trying my hardest to understand fully how sessions work and how best to use them. However, all I can find is information that doesn't tell me anything other than that sessions store...
13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
3
by: Maxime Ducharme | last post by:
Hi group We have a problem with sessions in one of our sites. Sessions are used to store login info & some other infos (no objects are stored in sessions). We are using Windows 2000 Server...
3
by: Will Woodhull | last post by:
Hi, I'm new here-- I've been reading the group for a couple of days. Nice group; I like the way n00b33 questions are handled. I've been using a Javascript routine in index.html to determine a...
2
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use...
12
by: D. Shane Fowlkes | last post by:
This is a repost (pasted below). Since my original post, I've double checked the system clock and set all IIS Session Timeout values to 10 minutes. Still ...the problem occurs. I've also...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
22
by: magic_hat60622 | last post by:
Hi all. I've got an app that dumps a user id into a session after successful login. the login page is http://www.mydomain.com/login.php. If the user visits pages on my site without the www (i.e.,...
13
Frinavale
by: Frinavale | last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
3
Atli
by: Atli | last post by:
Introduction: Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.