Click here to Skip to main content
11,581,515 members (59,453 online)
Rate this: bad
good
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 1:38am
Edited 16-Apr-13 1: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 at 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
0 OriginalGriff 340
1 Sergey Alexandrovich Kryukov 160
2 virusstorm 114
3 Frankie-C 105
4 RyanDev 84
0 OriginalGriff 1,273
1 Sergey Alexandrovich Kryukov 895
2 Abhinav S 597
3 F-ES Sitecore 500
4 Suvendu Shekhar Giri 433


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2015
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