Hi there....

I used UNIX htaccess for Log in to my web page. Inside my code I use MYSQL with PHP but everytime I closed the seeion for MYSQL.

Now my goal is to logo out from unix server and once I do that no matter how many same web page I have open will be logged out or inactive as for example in hotmail accout if you do log out once you cannot have access for the other hotmail window if there is any open one. I am using following code but it's not working. Please have a look and help me.....

Thank you.

<html> 
<head> 
<title> 
</title> 
</head> 
<body> 
<?php 
function logoutFromHTTP() 
{ 
unset($_SERVER['PHP_AUTH_USER']); 
unset($_SERVER['PHP_AUTH_PW']); 
} 


logoutFromHTTP(); 

print "Logout Successfull"; 
?> 
</body> 
</html> 

    I haven't used $SERVER before. But it looks like you could only have one person logged on per server. If I'm right you'll be better off user something like $SESSION. You'll also want to look at Session_Start(), Session_Name.

      I tired in different way. But some how it's not working and getting the following worning:

      Warning: Cannot add header information - headers already sent by (output started at /public_html/MainPage/logout2.php:7) in /public_html/MainPage/logout2.php on line 10

      Warning: Cannot add header information - headers already sent by (output started at public_html/MainPage/logout2.php:7) in /public_html/MainPage/logout2.php on line 11
      Logout Successfull

      Here is my new code. By the way I have my .htaccess file inside the Mainpage directory. And I put the logout2.php in the same directory. As I am a beginner in web designing I have very littile idea about the situation. Plese help me to find out the problem. Thank you.

      <html>
      <head>
      <title>
      </title>
      </head>
      <body>
      <?php
      
      
      header("WWW-Authenticate: Basic realm=\"My Realm\"");
      header('status: 401 Unauthorized');
      
      print "Logout Successfull";
      ?>
      </body>
      </html>
      
      

        The reason you are getting this error is because the web server was forced to send the headders when you sent the html. The headders have to be sent before the html begins, so it is pointless trying to send more once the html has begun.

        Try this:

        <?php 
        header("WWW-Authenticate: Basic realm=\"My Realm\""); 
        header('status: 401 Unauthorized'); 
        print "<html><head><title></title></head><body>";
        print_"Logout Successfull"; 
        print "</body></html>";
        ?>

        All I've changed is the order in which things happen. This should at least solve your current error. Remember to make sure that you don't event have one character before the <?php tag.

          I tried the following code:

          <?php

          header("WWW-Authenticate: Basic realm=\"My Realm\"");
          header('status: 401 Unauthorized');

          print "Logout Successfull";
          ?>

          Now I am getting a the same window for filling up the user id and password that I got first to log in to my web site as I used .htaccess file in side the MainPage directory.

          And if I press cancel it's giving me:

          Authorization Required
          This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

          If I press ok without inputting any thing it gives me:

          "Logout Successfull"

          Even I tried to fillup the user ID and password and press ok it gives me "Logout Successfull". I assume it's asking me the same user ID and Password that I used for the first login to for .htaccess file.

          But I don't want none of the above situations.

          Let me tell you my goal. I think that might help you to understand what I really want to do.

          I want to use some php code that will log me out from this web site and no matter how many pages are open from the same web sire (Those will be inactive). I mean you have to login again to get atarted again. Just think about hotmail. If it has open several pages from same user account. If you logout one of the page the others are required t olog in again on order to do something.

          Hope you understand. Plese let me know your advice.

            i may be wrong...but i believe you cannot have a logout for http auth. the only way (that i know of) or have read of from my own exploration is to close the browser. hotmail uses cookies (or sessions)...not http auth

              9 days later

              with IE you can logout by sending a link like

              <a href="http://noUser:noPassword@[url]www.yourdomain.com/logout.php[/url]">logout</a>

              it seems that ie overwrites $SERVER['PHP_AUTH_USER'] with 'noUser' and $SERVER['PHP_AUTH_PW'] with 'noPass' then.

              BUT:
              unfortunately it DOES NOT work with mozilla and opera.
              i did not test netscape.

              i would appreciate any ideas to make this work for all browsers.

                Write a Reply...