473,289 Members | 1,945 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,289 software developers and data experts.

logout script not working properly.

kamill
71
I have done a logout page for logout from admin section and provides a link to logout from admin section.Whenever i clicked on logout link it redirected to index.php of admin section......BUT when i am tring to go back threw back button of Browser....it send me last visted pages(means sessons not expire properly). How can i solve it... One more thing is that the script is working properly on localhost....problem occures when i uploaded it on server.
code of logout is following....
[php]<?phpsession_start();
if($_SESSION['user_id']!="" && $_SESSION['user_pwd']!="")
{
$_SESSION=array();
session_unset();
session_destroy();
?>
<script>
window.location.href="index.php";
</script>
<?php
}
else
{ ?>
<script>
window.location.href="index.php";
</script>
<?php } ?>[/php]
Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. - moderator
Jan 5 '07 #1
12 4553
cassbiz
202 100+
Not too familiar with the actual "logout" but I just checked a couple of different scripts that I have and they all call a logout or similar function.


Expand|Select|Wrap|Line Numbers
  1. logout();
Here is the function

Expand|Select|Wrap|Line Numbers
  1. function logout()
  2. {
  3.     $sql="UPDATE users
  4.     SET UserSession=NULL
  5.     WHERE UserSession='".session_id()."'";
  6.      mysql_query($sql);
  7. }
  8.  
Jan 5 '07 #2
Velhari
46
Hi,

You are facing the problem after logout, the user presses back button in the browser window it will shows all the pages visited by him/her earlier know.....

This problem can be easily removed by, you can check for the session variable for userid is set in each and every pages..... If suppose this condition is violated means, you have to forward it to the index page.....

Like just for an example...

[PHP]
session_start();
if ( $_SESSION['userid']=="" )
header("index.php");
[/PHP]


I have done a logout page for logout from admin section and provides a link to logout from admin section.Whenever i clicked on logout link it redirected to index.php of admin section......BUT when i am tring to go back threw back button of Browser....it send me last visted pages(means sessons not expire properly). How can i solve it... One more thing is that the script is working properly on localhost....problem occures when i uploaded it on server.
code of logout is following....
///////////////////////////////////////////////////////////////////////////////////////////////////
<?phpsession_start();

if($_SESSION['user_id']!="" && $_SESSION['user_pwd']!="")
{

$_SESSION=array();
session_unset();
session_destroy();
?>

<script>
window.location.href="index.php";
</script>
<?php

}

else
{ ?>

<script>
window.location.href="index.php";
</script>

<?php } ?>

/////////////////////////////////////////////////////////////////////////////////////////////
Jan 5 '07 #3
kamill
71
Hi,

You are facing the problem after logout, the user presses back button in the browser window it will shows all the pages visited by him/her earlier know.....

This problem can be easily removed by, you can check for the session variable for userid is set in each and every pages..... If suppose this condition is violated means, you have to forward it to the index page.....
Like just for an example...
[PHP]
session_start();
if ( $_SESSION['userid']=="" )
header("index.php");
[/PHP]
i have done it but it working on localhost but not working on server after uploading...my code is like this..
[php]<?php session_start();
if($_SESSION['username']=="" && $_SESSION['pwd']=="" )
{
?>
<script> window.location.href="index.php";</script>
<?php
}
else
{
rest of the code.....
}[/php]
2nd warning: Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

moderator
Jan 6 '07 #4
kamill
71
i am again putting my code in a mannered way.....help me ASAP
[PHP]<?php session_start();
if($_SESSION['username']=="" && $_SESSION['pwd']=="" )
{
?>
<script> window.location.href="index.php";</script>
<?php
}
else
{
rest of the code.....
}[/PHP]
Jan 8 '07 #5
kamill
71
Please help me as soon as possible......its very urgent for me.
thanks in advance....
Jan 9 '07 #6
kamill
71
i am waiting for help....
Jan 11 '07 #7
Markus
6,050 Expert 4TB
You have just posted this in a seperate thread.
Dont double post
Mar 8 '08 #8
Markus
6,050 Expert 4TB
i am waiting for help....
The session HAS expired, but you're viewing a cached version of the page.
I.E, the browser has stored that page in it's history.
Mar 8 '08 #9
TheServant
1,168 Expert 1GB
[PHP]<?php
session_start()
session_destroy()
?>

{redirect code}[/PHP]

This way it doesn't matter how many variables you have it will get rid of them all. If this doesn't work, it is the browser storing information somehow.
Mar 9 '08 #10
Markus
6,050 Expert 4TB
[PHP]<?php
session_start()
session_destroy()
?>

{redirect code}[/PHP]

This way it doesn't matter how many variables you have it will get rid of them all. If this doesn't work, it is the browser storing information somehow.
Like i already said, the browser stores the page in it's cache so people can use the back button.
Mar 10 '08 #11
Hi everbody,
I have also faced this kind of problem like session working in localhost and not working when uploaded, Now i got solution for this.
I have contact the hosting server and described the issue,then they came to my aid and help me out. The problem was "Due to some permission issue in session directory " that's why we were facing this problem.

The problem I faced and how it is solved i mention it,But i m not an expert!
thanks
Mar 11 '08 #12
here is a trick, before sending them to the home page after logout, send them to a redirect.php page which has only
[PHP]<?php
header("location: /index.php");
?>[/PHP]

That way, when they click the back button, its the redirect page which takes them back to the home page this will help resolve the issue of the cached pages, though they can still use the back drop down to go to whatever page they were on, it will make it harder, and many users may nbot realize this option
Mar 11 '08 #13

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

Similar topics

8
by: Harlin Seritt | last post by:
I have a remote linux server where I can only access it via ssh. I have a script that I need to have run all the time. I run like so: python script.py & It runs fine. When I log off ssh I...
25
by: crescent_au | last post by:
Hi all, I've written a login/logout code. It does what it's supposed to do but the problem is when I logout and press browser's back button (in Firefox), I get to the last login page. In IE,...
7
by: pank | last post by:
hey guys ... can anybody tell me a php logout script. I want to log out from one page which i was developing , i tried but it's not working. I have tried session_destroy(),session_unset()...
1
by: shrik | last post by:
hi everybody. I have following problem. There are two pages. index.jsp and main.jsp in my application Index.jsp contains logging interface in . It submits password and userid to loginform bean. ...
7
by: thesti | last post by:
hi, i'm learning and trying to develop a web with php. the logout script of mine seems not working since that after i pressed the logout link. i still get the greeting "welcome, 'username' ". ...
6
by: Thiago Macedo | last post by:
I could not find on the web a complete solution for this task. This is not the perfect solution, because it's doesn't have the ability to log the logout if browser crash or user leave it open while...
10
by: DavidPr | last post by:
When I logout as one user and log in under a different user, it opens with the last user's information. User 1 - Unsername: Davey Jones User 2 - Unsername: David Smith I log out from Davey...
3
by: waqasahmed996 | last post by:
Hi, I want to note time when user is logout. I can note time when user login and when logout properly(use button of logout). But if user is not used button and he closed his browser or...
1
by: phpuser123 | last post by:
Hi,I have created a script where I want to use onclick event and javascript to log out.Here r my coodes .. <script type="text/javascript"> function logout(){ <?php...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.