|
-
Jun 8th, 2001, 07:52 PM
#1
Thread Starter
Frenzied Member
php login
hi guys, how do I make a php login page, i dont need the usernames and passwords to be verified by a database, I just want to verift the username and pass right from the php code, how would i do this? if this isn't fairly easy, please send me in the right direction
thanks
~~~Dimava~~~
NXSupport - Your one-stop source for computer help
-
Jun 8th, 2001, 09:02 PM
#2
well if you don't use a database and you put the password and user ID in the script it won't be very secure.
you can do it by cookies and check against a database or you can have a file with emails and passwords and it checks agains that, but it still is like a database.
-
Jun 8th, 2001, 09:05 PM
#3
Thread Starter
Frenzied Member
so how would i make a file? i have never worked with php before
~~~dimava~~~
NXSupport - Your one-stop source for computer help
-
Jun 8th, 2001, 09:29 PM
#4
do you want to ba able to add the user to it or are you going to have fixed addresses in there?
-
Jun 8th, 2001, 09:41 PM
#5
Thread Starter
Frenzied Member
I want to be able to add the user, i just want a login page, and if the username/pass is correct, then proceed onto the next page (which is the same for all users). I am going to have about 100 users.
~~~Dimava~~~
NXSupport - Your one-stop source for computer help
-
Jun 8th, 2001, 10:31 PM
#6
ok sorry it took so long, but here it is.
Code:
<?php
$auth = false; // Assume user is not authenticated
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
// Read the entire file into the variable $file_contents
$filename = '/path/to/file.txt';
$fp = fopen( $filename, 'r' );
$file_contents = fread( $fp, filesize( $filename ) );
fclose( $fp );
// Place the individual lines from the file contents into an array.
$lines = explode ( "\n", $file_contents );
// Split each of the lines into a username and a password pair
// and attempt to match them to $PHP_AUTH_USER and $PHP_AUTH_PW.
foreach ( $lines as $line ) {
list( $username, $password ) = explode( ':', $line );
if ( ( $username == "$PHP_AUTH_USER" ) &&
( $password == "$PHP_AUTH_PW" ) ) {
// A match is found, meaning the user is authenticated.
// Stop the search.
$auth = true;
break;
}
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else {
header( 'Location: http://www.yourserver.com/new_page.html' );
}
?>
ok your password file is (file.txt) and change teh header location to what ever page you want the redirection to go to if their password checks out.
let me know if you need help and hope it works for ya.
-
Jun 8th, 2001, 10:34 PM
#7
oh ya I forgot the file.txt has to be like this
joe:ai890d
jane:29hj0jk
mary:fsSS92
bob:2NNg8ed
dilbert:a76zFs
to whatever you like. but in that format
-
Jun 10th, 2001, 10:23 PM
#8
Thread Starter
Frenzied Member
thanks for the code, one more question... how/where do I put the username and password text boxes? and i am getting errors on these lines:
PHP Code:
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
thanks,
Dimava
NXSupport - Your one-stop source for computer help
-
Jun 11th, 2001, 01:22 AM
#9
Well, it should have brought up the text boxes automatically. let me play around with it and find out. I will get back with ya
-
Jun 11th, 2001, 05:56 PM
#10
Thread Starter
Frenzied Member
NXSupport - Your one-stop source for computer help
-
Jun 12th, 2001, 04:36 PM
#11
sorry it has taken so long, but I can't seem to find out why it don't work. I have played around with it and I keep getting 500 errors. if you want to look I got the file from Zend.com
this might work better for ya.
http://www.zend.com/codex.php?id=168&single=1
also you can search around that site for more. I just have to say all teh code I get from there I can''t seem to get to work. like the one i got for you. oh wel you can try I guess.
sorry I couldn't help any further, that has me stumped as well, I will play around with it more
-
Jun 12th, 2001, 05:29 PM
#12
Thread Starter
Frenzied Member
thanks, the example on the website works great
~~~Dimava~~~
NXSupport - Your one-stop source for computer help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|