Advertisement
cascer1

PHP login auth

Sep 20th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2. //File will check if user is logged in.
  3. //If user is not logged in, will be redirected to the login page with an error.
  4. //Logged in users will be allowed access to the page.
  5. //Copyright 2012 Cas Eliëns and Dennis Koeter.
  6. $q=$_GET['q'];
  7. //$a is authentication level required.
  8. //if $a is 'u', regular user authentication is required.
  9. //if $a is 'a', administrative authentication is required.
  10.  
  11.  
  12. if($q=='u') {
  13.     if(isset($_SESSION['uid'])) {
  14.         $uid = $_SESSION['uid'];
  15.         }
  16.         else {
  17.         header("location:index.php?q=noauth"); }
  18.     }
  19.  
  20. elseif($q=='a') {
  21.     if(isset($_SESSION['perm'])) {
  22.         $perm = $_SESSION['perm'];
  23.         $uid = $_SESSION['uid'];
  24.         if($perm=='a') {
  25.             $authenticate = true;
  26.             }
  27.         elseif($perm=='u') {
  28.             header("location:noauth.php?q=u");
  29.             }
  30.         else {
  31.             header("location:noauth.php?q=e");
  32.             }
  33.         }
  34.     }
  35.  
  36. else {
  37.     header("location:index.php?q=noauth");
  38.     }
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement