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
https://forums.phpfreaks.com/topic/47534-solved-javascript-alert-message/
Share on other sites

<script language="javascript">

function confirmlink(link) {

    if ( confirm("Are you sure you want to navigate to this link?") )

      window.location = link;

}

</script>

<a href="javascript:confirmlink('http://www.link.com/link.html')">gogo</a>

 

something like this will help you I suppose

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.

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.