if (!isset($PHP_AUTH_USER)) { 
header('WWW-Authenticate: Basic realm="My Private Stuff"'); 
header('HTTP/1.0 401 Unauthorized'); 
echo 'Authorization Required.'; 
exit; 

else { 
echo "<P>You have entered this username: $PHP_AUTH_USER 
You have entered this password: $PHP_AUTH_PW 
The authorization type is: $PHP_AUTH_TYPE</p>"; 

?>

解决方案 »

  1.   

    <?php
    session_start();
    ?>
    <html>
    <head>
    <title>         </title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <font color=blue>
    <?php
    $conn=mysql_connect("localhost","root","");
    mysql_select_db("hdsoft",$conn);
    $query="select * from userinfo where userid='".chop($userid)."'";
    $result=mysql_query($query,$conn);
    $num=mysql_num_rows($result);
    if($num==0)
    {
         echo "<script language=\"javascript\">";
     echo "alert('用户名不存在!此窗口将要关闭!');";
     echo "window.opener=null;";
     echo "window.close();";
     echo "</script>";
    }
    else
     {
     $row=mysql_fetch_array($result);
     $usertype=$row[usertype];
    if($row[userpas]<>chop($passwd))
    {
     echo "<script language=\"javascript\">alert('密码不正确!此窗口将要关闭!');";
     echo " window.close();";
     echo "</script>";
    }
    else
    {
    if(!session_is_registered("userid1"))
    {
    $query="update userinfo set useraccount=useraccount+1 where userid=$userid";
    mysql_query($query,$conn);
    }
    $userid1=$userid;
    session_register("userid1");
    session_register("usertype");
    echo "<script language=\"javascript\">";
    echo "window.location=\"zjzx.php\";";
    echo "</script>";
    }
     }?>
    </font>
    </body>
    </html>
      

  2.   

    <?include("phputl/phputl.php");?>
    <?  $islogin=0;
      $errmsg='';
      session_unregister('ss_login_name');
      session_unregister('ss_c_name');
      session_unregister('ss_password');
      session_unregister('ss_login_time');
      if (isset($login)) {
         if (!$login_name){
           $errmsg='请输入登陆名';
           $islogin=0;
         }else{
           $db= new db_sql;
           $db->connect();
           $sql="select login_name,password,c_name,depart,email from user
                where login_name= '$login_name' and password='$password'";
           $db->query($sql);
           $db->next_record();
           if ($db->num_rows()) {
             $islogin=1;
             session_register('ss_login_name');
             session_register('ss_c_name');
             session_register('ss_password');
             session_register('ss_login_time');
             session_unregister('ss_id');
             $ss_login_name=$login_name;
             $ss_password=$password;
             $ss_c_name=$db->f('c_name');
        
             $ss_login_time=NowDateTime();
             
           }else{
             $errmsg='登陆名或口令错误';
             $islogin=0;
           }
         }
      }
      if ($islogin) {
        header("Location: http://$SERVER_NAME/work/");
      }
    ?>
    <?include"ad.php";?> 
    <html>
    <head>
    <title>日清总结</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <div align="center">
     <p><b><font size="6">日清总结</font></b></p>
     <? echo $errmsg; ?>
     <center><a href="mlogin.php">管理员入口</a></center>
      <form name="fm_login" method="post" action="<? echo $PHP_SELF;?>">
        <table width="34%" border="0">
          <tr>
            <td colspan="2" height="45">
              <div align="center">登录</div>
            </td>
          </tr>
                 <tr>
            <td height="19" width="35%">
              <div align="right">登录名</div>
            </td>
            <td height="19" width="65%">
              <input type="text" name="login_name" maxlength="16">
            </td>
          </tr>
          <tr>
            <td width="35%">
              <div align="right">口令</div>
            </td>
            <td width="65%">
              <input type="password" name="password" maxlength="16">
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <div align="center">
                <input type="submit" name="login" value="登录">
                <a href="reg.php">注册新用户</a></div>
                
            </td>
          </tr>
        </table>
        <br>
      </form>
    </div>
    </body>
    </html>
    <?
    include "foot.inc";
    <?php
    session_start();
     include_once("phputl/db_mysql.inc");  //定义全局变量
      //$_Debug=True; //用于程序调试
      $_MyServerName="192.168.100.56";
      $_MySelectdb="work";
      $_MydbUser="root";
      $_MyPassword="1234";
    //---------------------------------------------------------------------------------
    Function debug($var)  //用于程序调试
    {
      global $_debug;
      if ($_Debug){
         echo "<br>";
         echo "调试信息:------------------<br>";
         echo $Var."<br>";
         echo "---------------------------<br>";
      }
    };//---------------------------------------------------------------------------------
    Function dbQuery(   //返回数据库查询结果集
     $SqlStr="",
     $Server="",
     $UserName="",
     $Password="",
     $dbName="")
    {
      global $_MyServerName;
      global $_MySelectdb;
      global $_MydbUser;
      global $_MyPassword; if (!$SqlStr) return; debug($SqlStr,"SqlStr="); if (!$Server) $Server=$_MyServerName;
     if (!$UserName) $UserName=$_MydbUser;
     if (!$Password) $Password=$_MyPassword;
     if (!$dbName) $dbName=$_MySelectdb; $dbConnect=mysql_connect($Server,$UserName,$Password);
     //return mysql_db_query($dbName,$SqlStr,$dbConnect);
     mysql_select_db($dbName);
     return mysql_query($SqlStr,$dbConnect);};//---------------------------------------------------------------------------------
    Function dbGoTo($Query,$RecordNo)     //到指定行
    {
      mysql_data_seek($Query,$RecordNo);
    };//---------------------------------------------------------------------------------
    Function dbFieldCount($Query)
    {
      return mysql_num_fields($Query);
    };//---------------------------------------------------------------------------------
    Function dbFieldName($Query,$FieldNo)
    {
      return mysql_field_name($Query,$FieldNo);
    };//---------------------------------------------------------------------------------
    Function dbRecordCount($Query)
    {
      return mysql_num_rows($Query);
    };//---------------------------------------------------------------------------------
    Function dbNextRecordRead($Query)
    {
      return mysql_fetch_row($Query);
    };//---------------------------------------------------------------------------------
    Function dbRecordFieldRead($Query,$FieldName)
    {
      return mysql_Result($Query,0,$FieldName);
    };
    //---------------------------------------------------------------------------------
    Function NowDateTime()
    {
       return date("Y年m月d日 H时i分s秒");
    };
    //---------------------------------------------------------------------------------
    Function seetable(      //显示数据表的内容
       $Query,        //查询的数据集的名字
       $PageSize=10,  //每页显示表格的行数
       $PageGo=1,     //显示的页号
       $ngPage="",    //翻页按钮连接的页面
       $NotShowNo=0,  //是否显示序号
       $StartField=0,       //开始显示的字段
       $LinkPage1="",       //连接页1
       $KeyField1=0,  //连接的关键字段1
       $Label1="详细资料",  //连接标题
       $ShowModel1="_Self", //窗口显示方式(_self _Blank _top...)
       $LinkPage2="",       //
       $KeyField2=0,
       $Label2="详细资料",
       $ShowModel2="_Self")
    {
      $ii=0;
      $jj=0;
      $board=0;
      $hardBGcolor="#66cccc";
      $tableBGcolor="#99CCFF";  if (!$Query){
        echo "<br>Err:没有发现数据集!!<br>";
        return;
      };  $FieldCount=dbFieldCount($Query);
      $RecordCount=dbRecordCount($Query);  $PageCount=floor($RecordCount/$PageSize);
      if (($RecordCount%$PageSize)>0) $PageCount++;  if ($PageGo>$PageCount) $PageGo=$PageCount;
      if ($PageGo<1) $PageGo=1;  if ($RecordCount>0){
        echo "页".$PageGo."/".$PageCount." 共".$RecordCount."条纪录";
        $PageStartRow=($PageGo-1)*$PageSize;
        dbGoTo($Query,$PageStartRow);
       }
      else{
        echo "没有查询的资料";
        Return;
      };  echo "<table border=$board>";
      echo "<tr bgcolor=$hardBGcolor>";  if (!$NotShowNo) echo "<td>序</td>";
      for ($ii=$StartField;$ii<$FieldCount;$ii++)
        echo "<td> ".dbFieldName($Query,$ii)."</td>";  If ($LinkPage1<>"") echo "<td>$Label1</td>";
      If ($LinkPage2<>"") echo "<td>$Label2</td>";
      echo "</tr>";  for ($jj=1;$jj<=$PageSize;$jj++){
        $AryRow=dbNextRecordRead($Query);
        if (!$AryRow) break;
        echo "<tr bgcolor=$tableBGcolor>";
        if (!$NotShowNo) echo "<td>".($jj+(($PageGo-1)*$PageSize))."</td>";
        for ($ii=$StartField;$ii<$FieldCount;$ii++)
      echo "<td> ".$AryRow[$ii]."&nbsp;</td>";    //建立连接标签1
        if ($LinkPage1<>""){
          echo "<td><a href=\"$LinkPage1?Key=";
          echo $AryRow[$KeyField1];
          echo "\" target=$ShowModel1";
          echo ">".$Label1."</a></td>";
        };
       //建立连接标签2
        if ($LinkPage2<>""){
          echo "<td><a href=\"$LinkPage2?Key=";
          echo $AryRow[$KeyField2];
          echo "\" target=$ShowModel2";
          echo ">".$Label2."</a></td>";
        };    echo "</tr>";
      };
      echo "</table>";
      //显示翻页按钮
      if ($ngPage!=""){
        if ($PageGo>1){
          echo "<a href=$ngPage?page=1>首页</a>";
          echo "<a href=$ngPage?page=".($PageGo-1).">上页</a>";
          echo "下页";
          echo "末页";
        }elseif ($PageGo<$PageCount){
          echo "首页";
          echo "上页";
          echo "<a href=$ngPage?page=".($PageGo+1).">下页</a>";
          echo "<a href=$ngPage?page=$PageCount>末页</a>";
        }
      }
    }; //enf function seetable()//---------------------------------------------------------------------------------
    Function islogin()
    {
      return session_is_registered("ss_login_name");
    };//----------------------------------------------
      

  3.   

    我用类写de ,不过phpl.php中只有session_start()和自定义函数islogin()有用每一次用session时都要session_start()