HTTP Authentication with PHP

New to PHP 4.0 is the ability to do HTTP authentication, althrough It is available only when running PHP as a module with Apache.


  ex.: 


  Header('www-authenticate: basic realm = "some caption or text" ');


  Header('HTTP / 1.0 401 Unauthorized');


  ex.: 


  • Data can be Access via the following;   

   ex.: 


  $_SERVER['PHP_AUTH_USER']

  $_SERVER['PHP_AUTH_PW']



  Sample Code for review : 


  $query = 'SELECT first_name from users where username = '{$_SERVER['PHP_AUTH_USER']}'

                password = password('{$_SERVER['PHP_AUTH_PW']}');

  $result = @mysql_query($query);

  $row = @mysql_fetch_array($result);

  IF ($row) {

       . . . . .

       . . .

  }