Jump to content

[SOLVED] javascript alert message


verN

Recommended Posts

hi,

 

i have the following code that enables a user to be logged out. This works perfectly however i now wish a confirmation dialog to appear asking to user to confirm thier actions but how do I do this in this code:

 

 

<?php

  session_start();

  session_destroy();

 

 

  $logout = "login.php";

  header("Location: $logout");

 

?>

 

thanks in advance

Link to comment
Share on other sites

to logout user must have to click on a logout button or link I suppose. If link's href is like that, a confirmation message will show. You are not stopping your php code and you will not be able combine both I think. You can only ask for cofirmation at the moment where user clicks on logout button. I do not know any function in php which will pause the script and ask for user's confirmation.

Link to comment
Share on other sites

You can't have the confirmation on the same page as the PHP code that logs them out. By the time the JS alert box is seen, the PHP logout action will have already been committed. What you need to do is attach the confirmation to your logout button or link:

 

<a href="logout.php" onclick="return confirm('Are you sure you wish to logout?');">Logout</a>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.