verN Posted April 18, 2007 Share Posted April 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
radalin Posted April 18, 2007 Share Posted April 18, 2007 <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 Quote Link to comment Share on other sites More sharing options...
verN Posted April 18, 2007 Author Share Posted April 18, 2007 how to I combine javscript and php to do this thnaks Quote Link to comment Share on other sites More sharing options...
radalin Posted April 18, 2007 Share Posted April 18, 2007 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. Quote Link to comment Share on other sites More sharing options...
verN Posted April 18, 2007 Author Share Posted April 18, 2007 how do i do this this is bugging me Quote Link to comment Share on other sites More sharing options...
fenway Posted April 20, 2007 Share Posted April 20, 2007 how do i do this this is bugging me Do what? Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 20, 2007 Share Posted April 20, 2007 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.