admin 发表于 2008-1-3 02:45:25

Protect a PHP page 加密PHP页面

$pass = "YOUR PASSWORD HERE";
$user = "YOUR USERNAME HERE";

<?php
      session_start(); //initiates the sessions
      if      ($_POST[’submit’])//checks to make sure the login form has been submitted
      {
      $pass = "YOUR PASSWORD HERE";
      $user = "YOUR USERNAME HERE";
      if      ($_POST[‘pass’] == $pass && $_POST[‘user’] == $user)//checks if the password submitted by the user matches the password stored in the $pass variable
      {
      $_SESSION[‘access’]   = 1;//if login is successful create a session that can be authenticated
      header("Location: " . $_SERVER[‘PHP_SELF’]);//reload the page. The page will now not load the login form (see the first if condition)
      }
      else// if password is incorrect reload the login form
      {
      header("Location: " . $_SERVER[‘PHP_SELF’]);
      }
      }
      else if (!$_SESSION[‘access’])//if the "access" session is not accessible show the form (not logged in)
      {?>
      <form action="<?php echo $_SERVER[’PHP_SELF’]; ?>" method="post">
      <table align="center" cellpadding="3" cellspacing="3">
      <tr>
      <td bgcolor="#F7F7F7">Username:</td>
      <td bgcolor="#F7F7F7"> <input name="user" type="text" /></td>
      </tr>
      <tr>
      <td bgcolor="#F7F7F7">Password</td>
      <td bgcolor="#F7F7F7"><input name="pass" type="text" /></td>
      </tr>
      <tr>
      <td colspan="2" bgcolor="#F7F7F7"><div align="center">
      <input name="submit" type="submit" value="Login">
      </div></td>
      </tr>
      </table>
      </form>
      <?php
      exit;
      }
      ?>

hbthomes 发表于 2008-2-29 16:01:15

正需要推广呢.谢谢

正需要推广呢.谢谢

poeeop 发表于 2008-3-28 09:43:48

谢谢分享。。。。。。。。
页: [1]
查看完整版本: Protect a PHP page 加密PHP页面