PHP quick Login protect script


  1. <?php
  2. session_start();
  3.  if (!isset($_SESSION['ok']) || $_SESSION['ok'] !== true) {
  4.  if(isset($_POST['login']) && isset($_POST['pass'])) {
  5.    if($_POST['login'] == 'user' && $_POST['pass'] == 'password') {
  6.      $_SESSION['ok'] = true;
  7.      header('Location: '.$_SERVER["php_SELF"].'?' .urlencode(session_name()) . '=' . urlencode(session_id()));
  8.    } else {
  9.      echo 'Login leider falsch.';
  10.      $_SESSION['ok'] = false;
  11.    }
  12.  }
  13.  ?>
  14.  <form method="post">
  15.    Login: <input type="text" name="login" />
  16.    Passwort: <input type="password" name="pass" />
  17.    <input type="submit" value="login" />
  18.  </form>
  19.  <?php
  20.  } else {
  21.  // Authenticated user
  22. ?>
  23. Secure content
  24. <?php
  25. }
  26. ?>

Trackback URL for this post:

http://www.2030.tk/trackback/175

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Use <fn>...</fn> to insert automatically numbered footnotes.
  • You can use the <go> tags just like the <a> for nicer urls.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.