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 Link to comment https://forums.phpfreaks.com/topic/47534-solved-javascript-alert-message/ 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 Link to comment https://forums.phpfreaks.com/topic/47534-solved-javascript-alert-message/#findComment-232042 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 Link to comment https://forums.phpfreaks.com/topic/47534-solved-javascript-alert-message/#findComment-232053 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. Link to comment https://forums.phpfreaks.com/topic/47534-solved-javascript-alert-message/#findComment-232057 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 Link to comment https://forums.phpfreaks.com/topic/47534-solved-javascript-alert-message/#findComment-232539 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? Link to comment https://forums.phpfreaks.com/topic/47534-solved-javascript-alert-message/#findComment-233908 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> Link to comment https://forums.phpfreaks.com/topic/47534-solved-javascript-alert-message/#findComment-233911 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.