473,382 Members | 1,745 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,382 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 4556
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.