前提:文件本身必须可写~~~!Unix下面设置为777<?
// 管理密码,运行时会要求输入
$password = "yeew.net" ;function update($file,$j,$str)
{
 /*
 函数说明:修改本文件$file的第$j行,将$str字符写入第$j行
 */
   $newfile = "";
   $fc=file($file);
   $f=fopen($file,"r");
   flock($f,LOCK_SH);
   for ($i=0;$i<count($fc);$i++)
   {
         if ($i == $j)
         {
          $newfile = $newfile."\$password = \"".$str."\";\n";
         }
         else
         {
         $newfile = $newfile.$fc[$i]."";
         }
   }
     fclose($f);
     $f=fopen($file,"w");
     flock($f,LOCK_EX);
     fputs($f,$newfile);
     fclose($f);
}session_start();if($_POST['newpsw'])
{
  update(update($_SERVER['SCRIPT_FILENAME '],3,$_POST['newpsw']);  ##调用函数更改密码,前提是这个文件必须设置为可写
 exit;
}if ( $password == "yeew.net" )
{
        HtmlHead("需要重设管理员密码:") ;
        echo "<h3 align=center>您没有修改管理密码,为避免不安全,请修改成其它的!</h3>";
        echo "<form name=\"changepsw\" method=\"post\" action=\"\">";
        echo "<br><input name=\"newpsw\" type=\"text\" size=\"20\"><br>";
        echo "<input name=\"submitnpsw\" type=\"submit\" value=\"更改密码\">";
        echo "</form>";
        hg_exit();
}if ( !IsSet($_SESSION['administrator']) )
{
        if ( !IsSet($_POST['user_pass']) )
        {
                HtmlHead("输入管理员密码:");
                echo '<h3 align="center">为安全起见,以下操作需要密码认证:</h3>';
                hg_exit('<br><form action=' . $_SERVER['PHP_SELF']
                        . ' method="post">请输入密码:<input name="user_pass"> <input type="submit" name=\"submit\" value="确定"> </form>');
        }
        else
        {
                if ( $password != $_POST['user_pass'] )
                {
                        HtmlHead("错误的管理员密码!");
                        MessageBox("错误的管理员密码, 无法继续操作! 如果您忘了密码,可以在本文件的第二行查到密码!", true);
                        hg_exit("", true);
                }
                $_SESSION['administrator'] = "seted";
                header("Location: {$_SERVER['PHP_SELF']}");
        }
        hg_exit();
}?>