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

    Create a new page, let's say "login_confirm.php"...

    Simply write :

    Are you really sure you want to logout?

    Yes -> logout.php
    No -> another_page.php

    Logout being the code you wrote above...

      isn't there a way i could use it on the same script

        Of course...

        <?php
         if(isset($_GET['logout'])) {
           session_start();
           session_destroy();
        
        
           $logout = "login.php";        
        header("Location: $logout"); exit(); } echo 'Are you sure you want to logout?' . "\n"; echo '<p>' . "\n; echo ' <a href="' . $_SERVER['SCRIPT_NAME'] . '?logout=1">Yes</a> | <a href="another_page.php">No</a> echo '</p>' . "\n; ?>

          isn't there a way to do this with javascript since it will be alot neater
          <?php
          session_start();
          session_destroy();

          // redirects the user
          //$logout = "login.php";
          //header("Location: $logout");
          //exit();

          ?>
          <script language="javascript">
          function confirmlink(link) {
          if ( confirm("Are you sure you want to log out?"))
          window.location = "login.php";
          }
          </script>

          thanks

            Yes...

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

            Will work as long as someone has JavaScript activated. Otherwise, it will log out without confirmation.

              it doesn't work it takes the user back to login page without confirming.

              <?php
                 session_start(); 
                 session_destroy(); 
              
              
                 $logout = "login.php";         
              header("Location: $logout"); exit(); ?> <script language="javascript"> function confirm() { if ( confirm("Are you sure you want to log out?")) window.location = "login.php"; } </script>

                No, the JavaScript stuff needs to be put in a NORMAL webpage, not in the logout page !

                Look at your code... you wrote header("Location: ..."), and then exit() ! How do you want the rest of the code to be executed after calling exit() ?!

                When I wrote the little link above, I had in mind you would put it in every page of your site, just like on many forums where there's always a logout button !

                Also, you can't create a JavaScript function confirm() since there's a built-in function with that name...

                  how would I do this sorry but i still don't understand

                    Write a Reply...