Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to make a Control Panel for admins with a $_SESSION.
Now I have created a javascript controlled button that asks to terminate the current session, and that will make it to delete the $_SESSION ((unset it)).

I have used this javascript code:
JavaScript
<script type="text/javascript">function Test() {
		var _endSession = confirm("End current editing session ?");
		if(_endSession == true)
		{
			<?php
				unset($_SESSION['."'UsernameChosen'".');
			?>
			alert("Session terminated.");
		}
		else
		{
			alert("Session active.");
		}
	}</script>


If I remove the tag, it'll work with only the alerts.
But if I remove the unset it still wouldn't work. So I just assumed that the php tags in javascript aren't functioning right, did I do anything wrong or is php isn't workable in javascript ? If it isn't how could I do this function script ?
Posted
Updated 16-Apr-13 1:42am
v2

1 solution

you cannot use like this the correct way is

JavaScript
<script type="text/javascript">function Test() {
		var _endSession = confirm("End current editing session ?");
		if(_endSession == true)
		{
                      
							unset($_SESSION['."'UsernameChosen'".');
			?>
                       <script>
			alert("Session terminated.");
		}
		else
		{
			alert("Session active.");
		}
	}</script>



</script>
 
Share this answer
 
Comments
NextGenDeveloper 16-Apr-13 7:55am    
Thanks alot, it wasn't the fully working code that you gave me, but I handled to fix it.

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