log out confirmation

Hello, I want a javascript that will give the user promt to confirm if he want to log out

here is the log out page code
<?php require_once("includes/functions.php"); ?>
<?php
		// Four steps to closing a session
		// (i.e. logging out)
 
		// 1. Find the session
		session_start();
		
		// 2. Unset all the session variables
		$_SESSION = array();
		
		// 3. Destroy the session cookie
		if(isset($_COOKIE[session_name()])) {
			setcookie(session_name(), '', time()-42000, '/');
		}
		
		// 4. Destroy the session
		session_destroy();
		
?>

Open in new window

MrFahadAsked:
Who is Participating?
 
Ray PaseurConnect With a Mentor Commented:
@MrFahad: by the time you get to this script, it's too late!  A better place might be on the link to the logout script.  You can use the built-in window.confirm like this:

HTH, ~Ray
<a href="/logout.php" onClick="return confirm('Are you sure you want to Log Out');">Logout</a>

Open in new window

0
 
masheikCommented:
hi
 this link will help you,
http://wildphp.com/
 
0
 
agamalCommented:
i think you need to change the logout button to look like the code attached .....

and keep the logout.php code as it is

<script type="text/javascript">
function logconfirm() {
var answer = confirm("Text or question you want to use");
if (answer== true)
 {
   window.location="logout.php";
 } }
</script>
<input type="button" onClick="logconfirm()" name="logout" value="logout">

Open in new window

0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
MrFahadAuthor Commented:
Thanks Ray, Great gay always give simple and easy answer yet very handy :D
0
 
Ray PaseurCommented:
Thanks for your kind words and for the points!  Enjoy your project, ~Ray
0
 
MrFahadAuthor Commented:
your welcome ray, by the way please take a look at my problem here:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24166113.html

:)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.