Connecting Tech Pros Worldwide Forums | Help | Site Map

logout script not working properly.

kamill's Avatar
Member
 
Join Date: Dec 2006
Location: within compiler
Posts: 65
#1: Jan 5 '07
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

cassbiz's Avatar
Familiar Sight
 
Join Date: Oct 2006
Location: Florida
Posts: 204
#2: Jan 5 '07

re: logout script not working properly.


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.  
Member
 
Join Date: Sep 2006
Location: Chennai, INDIA
Posts: 46
#3: Jan 5 '07

re: logout script not working properly.


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]


Quote:

Originally Posted by kamill

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 } ?>

/////////////////////////////////////////////////////////////////////////////////////////////

kamill's Avatar
Member
 
Join Date: Dec 2006
Location: within compiler
Posts: 65
#4: Jan 6 '07

re: logout script not working properly.


Quote:

Originally Posted by Velhari

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
kamill's Avatar
Member
 
Join Date: Dec 2006
Location: within compiler
Posts: 65
#5: Jan 8 '07

re: logout script not working properly.


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]
kamill's Avatar
Member
 
Join Date: Dec 2006
Location: within compiler
Posts: 65
#6: Jan 9 '07

re: logout script not working properly.


Please help me as soon as possible......its very urgent for me.
thanks in advance....
kamill's Avatar
Member
 
Join Date: Dec 2006
Location: within compiler
Posts: 65
#7: Jan 11 '07

re: logout script not working properly.


i am waiting for help....
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,940
#8: Mar 8 '08

re: logout script not working properly.


You have just posted this in a seperate thread.
Dont double post
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,940
#9: Mar 8 '08

re: logout script not working properly.


Quote:

Originally Posted by kamill

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.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 914
#10: Mar 9 '08

re: logout script not working properly.


[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.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,940
#11: Mar 10 '08

re: logout script not working properly.


Quote:

Originally Posted by TheServant

[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.
Newbie
 
Join Date: Mar 2008
Location: Hyderabad
Posts: 17
#12: Mar 11 '08

re: logout script not working properly.


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
RoninOni's Avatar
Newbie
 
Join Date: Mar 2008
Posts: 9
#13: Mar 11 '08

re: logout script not working properly.


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
Reply


Similar PHP bytes