Click here to Skip to main content
12,071,437 members (35,387 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Javascript HTML PHP
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:
<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 16-Apr-13 2:38am
Edited 16-Apr-13 2:42am
v2

1 solution

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

Solution 1

you cannot use like this the correct way is

<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>
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2016
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