Click here to Skip to main content
13,043,654 members (52,996 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have the following code in php:

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

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 16-Apr-13 2:26am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100