PHP_in by xiaoyounan

VIEWS: 10 PAGES: 4

									登入設計
               登入設計-不使用資料庫
Index.php
<?
if (empty($_SERVER['PHP_AUTH_USER']))
{
 header("Content-type:text/html;charset=big5");
 header('WWW-Authenticate: Basic realm="\confirm\"');
 header('HTTP/1.0 401 Unauthorized');
 echo '請輸入正確的帳號與密碼';
 exit;
}else
{
 echo "帳號:".$_SERVER['PHP_AUTH_USER']."<BR>";
 echo "密碼:".$_SERVER['PHP_AUTH_PW']."<BR>";
 $CORRECTNAME="rueychi";
 $CORRECTPW="rc0531";
  if (($_SERVER['PHP_AUTH_USER'] !=$CORRECTNAME) or
($_SERVER['PHP_AUTH_PW']!=$CORRECTPW))
   {
     echo "登入失敗";
   }else
   {
     ECHO "成功.";
   }
}
?>
                      登入設計-使用資料庫
Index1.php
<?
if (empty($_SERVER['PHP_AUTH_USER']))
{
 header("Content-type:text/html;charset=big5");
 header('WWW-Authenticate: Basic realm="認證範圍XXX"');
 header('HTTP/1.0 401 Unauthorized');
 echo '請輸入正確的帳號與密碼';
 exit;
}else
{
 echo "帳號:".$_SERVER['PHP_AUTH_USER']."<BR>";
 echo "密碼:".$_SERVER['PHP_AUTH_PW']."<BR>";
 // 使用資料庫取代
 $linkptr=mysql_pconnect("localhost","root","");
 mysql_select_db("passcheck",$linkptr);
// $querystring="select * from account where username ='" . $_SERVER['PHP_AUTH_USER'] . "' and
userpassword=password('" . $_SERVER['PHP_AUTH_PW'] . "')";
 // 資料庫加密後不正確
 $querystring="select * from account where username ='" . $_SERVER['PHP_AUTH_USER'] . "' and
userpassword='" . $_SERVER['PHP_AUTH_PW'] . "'";
 $result=mysql_query($querystring,$linkptr);
 $num=mysql_num_rows($result);
 if ($num!=1){
    echo "登入失敗";
 }else{
    ECHO "成功.";
 }
}
                   登入設計-驗證

confirm.php
<? include "index1.php"; ?>
<html>
 this is a test
</html>

Confirm1.php
<? include "index1.php"; ?>
<html>
再次測試
</html>

								
To top