Re: [PHP-DB] using Flat File

2003-01-22 Thread Addison Ellis
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="This account 
exists,\n  
 but you have not entered the\n 
 correct password!\n Please try again.";
   include("login_form.php");  
 }
  }
  elseif ($num == 0)  // login name not found  
  {  
 unset($do);   
 $message = "The eMail 
Address you entered\n 
 can't be found!\n Please try again or\n
Create a New Account.";
 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



 $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" ) &&
  ( $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 'You are authorized!';

 > }


 ?>







-
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
[EMAIL PROTECTED]
[EMAIL PROTECTED]
subsidiaries of small independent publishing co.
[EMAIL PROTECTED]
[EMAIL PROTECTED]


Re: [PHP-DB] using Flat File

2003-01-22 Thread John Krewson
Check to see if $PHP_AUTH_USER exists by echoing it to the browser,
and make sure you have permissions to the txt file you are trying to read.

That's all I can think of given the lack of information such as error 
messages, where it breaks, etc.


web man wrote:

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

$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" ) &&
> ( $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 '

You are authorized!

';
>}
>
>?>
>
>




-
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now


--
John Krewson
Programmer - SWORPS


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP-DB] using Flat File

2003-01-22 Thread Hutchins, Richard
What do you mean the code doesn't work? How is the code behaving? What kinds
of errors are being returned by the interpreter? Is your register_globals
set to ON or OFF? Are you certain you have access to the directory in which
the file you wish to open is located?

> -Original Message-
> From: web man [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 22, 2003 2:02 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] using Flat File
> 
> 
> 
> 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 
> 
>  >
> > $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" ) &&
> >  ( $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 'You are authorized!';
> > }
> >
> > ?>
> >
> >
> 
> 
> 
> 
> -
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP-DB] using Flat File

2003-01-22 Thread web man

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 


> $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" ) &&
>  ( $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 'You are authorized!';
> }
>
> ?>
>
>




-
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now


[PHP-DB] using Flat File

2003-01-21 Thread web man

Hi Guys,

i wondered if there any assistance you could do for me on this code.

I have called on God many times to assist me but He did not respond.

I hope you would.

What I am trying to do is to allow certain users to view a certain page . I stored 
their names and passwords in a file.txt

But the is not working is there any help??

You are authorized!';  
}  

?>  





-
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now