Re: using Flat File

From: Date: Wed, 22 Jan 2003 22:27:09 +0000
Subject: Re: using Flat File
Groups: php.db 
Request: Send a blank email to php-db+get-25051@lists.php.net to get a copy of this message
here is what i use. have your login_form.php post to this and call this login.php. hope it helps. addison <?
  session_start();                                          session_register('auth');                                      session_register('logname');
  include("config.php");   //this file ("config.php") contains the database connection info.                                                                         {
    case "login":
      $sql = "SELECT username FROM accounts                                   WHERE username='$username'";
      $result = mysql_query($sql)
                  or die("Couldn't execute query1.");
      $num = mysql_num_rows($result);                                if ($num == 1)  // login name was found                     {
         $sql = "SELECT username FROM accounts                                   WHERE username='$username'
                 AND password='$password'";
         $result2 = mysql_query($sql)
                   or die("Couldn't execute query2.");
         $num2 = mysql_num_rows($result2);
         if ($num2 > 0)  // password is correct                         {
$auth="yes";                                                                             $logname=$username;                                           $today = date("Y-m-d h:m:s");                                  $sql = "INSERT INTO login (username,logintime) //this is a login table in the db. not necessarily needed.
                   VALUES ('$username','$today')";
           mysql_query($sql) or die("Can't execute query login.");
           header("Location: where_you_want_user_to_go_if_authorized.php");                         }
         else    // password is not correct                             {                                                    $message="<font face=verdana size=1 color=red>This account exists,\n                           but you have not entered the\n                      correct password!\n Please try again.</font>";
           include("login_form.php");                                   }
      }                                                              elseif ($num == 0)  // login name not found                    {           unset($do);                                                    $message = "<font face=verdana size=1 color=red>The eMail Address you entered\n                          can't be found!\n Please try again or\n
                                Create a New Account.</font>";
         include("login_form.php"); //this is the file that actually contains the log in text fields
      }
?>                                       
Hi, I have posted my question to this list before but I did not get a help that I was expected. All I wanted to do is to give access for the users to view a page in which the below code is embedded. The user will enter his/her username and password. But the code is not working. I don't know what to think. I need your help guys. Don't let me die on this code <?php
$auth = false; if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
     $filename = 'c:\\php_data\\file.txt';
     $f = @fopen($filename, "r");
      if ($f != FALSE)
      {    $a = @fread($f, filesize($filename));
             fclose($f);
      }
      else
      {
           echo "Could not open file";
      }
     $lines = explode ( "\n", $file_contents );
     foreach ( $lines as $line ) {
         list( $username, $password ) = explode( ':', $line );
         if ( ( $username == "$PHP_AUTH_USER" ) &amp;&amp;
              ( $password == "$PHP_AUTH_PW" ) ) {
             $auth = true;
             break;
         }
     }
} if ( ! $auth ) {
     header( 'WWW-Authenticate: Basic realm="Private"' );
     header( 'HTTP/1.0 401 Unauthorized' );
     echo 'Authorization Required.';
     exit;
} else {
     echo '<P>You are authorized!</P>';
}
?>
--------------------------------- Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now
-- Addison Ellis small independent publishing co. 114 B 29th Avenue North Nashville, TN 37203 (615) 321-1791 addison@bellsouth.net info@smipco.com subsidiaries of small independent publishing co. info@gloabaldog.com info@momandpocentral.com

« previous php.db (#25051) next »