Click here to Skip to main content
15,665,319 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
a.php
here i have my html form , when i log in i save my state as loge in so when i press the return browser button it will check my state if i am loged in then it will not allow
PHP
<?php
session_start();
$_SESSION['login_state'];
?>
<?php
if($_SESSION['login_state'] == "loged in")
header("location:b.php");
?>
<html>
<body>
<form name="form1" method="post" action="b.php">
username :<input type="text"/>
</br>
submit :<input type="submit"/>
</form>

</body>

</html>


b.php
here i have a link to log out but before i go to a.php again i have to reset my state to loged out to allow user to return to log in page ,

Java
<script type="text/javascript">
function logout()
{
	<?php
	$_SESSION['login_state']="loged out";
	header("location:a.php");
	?>
}
</script>
<?php
session_start();
$_SESSION['login_state']="loged in";
echo $_SESSION['login_state'];
?>
<html>
<body>
<a href="#"  önClick="logout()">logout</a>
</body>
</html>


how can i do this for all my pages , if the user press the browser return button i want to get an alert message saying do you wanna log out or do you want to save changes before leaving this page???? , Thank you
Posted
Updated 9-Nov-13 1:55am
v2

1 solution

I think you mean if someone clicks log out when they have typed something ? Have a variable that gets set to true whenever any value changes on the page, and then check that to show your pop up if someone clicks logout.

Don't use hard coded strings in your session. If someone who can spell 'logged out' works on this code, they will have trouble. Set the state to true or false. If you must use strings, create a class to store them so they are strongly typed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900