Click here to Skip to main content
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 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 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 200
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2014
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