Advertisement
mrengy

authenticate.inc.php

Aug 5th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. <?php
  2. if (!file_exists($userlist) || !is_readable($userlist)){
  3.     $error = 'Login facility unavailable. Please try later.';
  4. }
  5. else{
  6.     //read the file into an array called $users
  7.     $users = file($userlist);
  8.     //loop through the array to process each line
  9.     for ($i = 0; $i < count($users); $i++){
  10.         //separate each element and store in a temporary array
  11.         $tmp = explode(', ', $users[$i]);
  12.         //check for a matching record
  13.         if ($tmp[0] == $username && rtrim($tmp[1]) == $password){
  14.             $_SESSION['authenticated'] = 'Jethro Tull';
  15.             session_regenerate_id();
  16.             break;
  17.         }
  18.     }
  19.     //if the session variable has been set, redirect
  20.     if (isset($_SESSION['authenticated'])){
  21.         header("Location: $redirect");
  22.         exit;
  23.     }
  24.     else {
  25.         $error = 'Invalid username or password.';
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement