Click here to Skip to main content
14,865,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following code in php:

PHP
echo '<head><script type="text/javascript">function EndSession() {
		var _endSession = confirm("End current editing session ?");
		if(_endSession == true)
		{';
				unset($_SESSION['UsernameC']);
			echo 'alert("Session terminated.");
			window.location = "index.php?page=acp";
		}
		else
		{
			alert("Session active.");
		}
	}</script></head>';


You can notice the ' unset($_SESSION['UsernameC']); ' is part of the php script, that ment to run only inside the javascript, but it runs anytime, is there any way to fix it ?
Posted

1 solution

PHP
unset($_SESSION['UsernameC']);


This is server-side code, and will run when the page is being "rendered" in server to be sent to the client.

Your javascript runs in the client side, that don't have direct access to the server-side code.

Maybe you could create a logout page that remove the user session and then redirects him to the index page or you could do the session logout through an Ajax call.

What you need to have in mind is:

PHP -> server-side code

javascript -> client-side code

and that client and server code don't have direct access to each other.

Hope it helps.
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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