PHP 4

[ PHP ]

(!!! Teleportom!!!)
: fopen, msql_num_fields, socket_write ...


17. HTTP- PHP

HTTP- PHP Apache- , , CGI-. - Apache- header() "Authentication Required" , Username/Password. username password, URL PHP-, $PHP_AUTH_USER, $PHP_AUTH_PW $PHP_AUTH_TYPE, , , . "Basic". . header().

, :
17-1. HTTP
<?php
  if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header("WWW-Authenticate: Basic realm=\"My Realm\"");
    header("HTTP/1.0 401 Unauthorized");
    echo ",    ,
        Cancel\n";
    exit;
  } else {
    echo "<p>Hello {$_SERVER['PHP_AUTH_USER']}.</p>";
    echo "<p>   {$_SERVER['$PHP_AUTH_PW']}.</p>";
  }
?>

: , HTTP header'. , "Basic" "B" , /realm ( ), "401" "HTTP/1.0 401" header'.

$PHP_AUTH_USER $PHP_AUTH_PW, , , username password dbm-.

Internet Explorer. header'. WWW-Authenticate header HTTP/1.0 401 header .

- , , , PHP_AUTH , . $REMOTE_USER .

: PHP AuthType , . , PHP ( ).

, , , URL, URL .

Netscape Navigator, Internet Explorer /realm 401 . "log out" ( ) , username password. "time out" , "log-out".

17-2. HTTP , name/password
<?php
  function authenticate() {
    header( "WWW-Authenticate: Basic realm=\"Test Authentication System\"");
    header( "HTTP/1.0 401 Unauthorized");
    echo "    login ID       \n";
    exit;
  }
 
if (!isset($_SERVER['PHP_AUTH_USER'])||($SeenBefore == 1 && $OldAuth == $_SERVER['$PHP_AUTH_USER'])))
  {
   authenticate();
  } 
  else {
   echo "<p>Welcome: {$_SERVER['$PHP_AUTH_USER']}<br>";
   echo "Old: {$_REQUEST['$OldAuth']}";
   echo "<form action='{$_SERVER['$PHP_SELF']}' METHOD='POST'>\n";
   echo "<input type='hidden' name='SeenBefore' value='1'>\n";
   echo "<input type='hidden' name='OldAuth' value='{$_SERVER['$PHP_AUTH_USER']}'>\n";
   echo "<input type='submit' value='Re Authenticate'>\n";
   echo "</form></p>\n";
  }
?>

HTTP Basic authentication, . Lynx , Lynx 401 , back, forward, , . , , '_' .

, Microsoft IIS- CGI- PHP - IIS.

: safe mode , uid realm WWW-Authenticate.




: 3119 .

: - |  -