login with header("WWW-Authenticate: Basic realm=\"example\"");

Messages
341
Reaction score
0
Points
0
I know this is a stupid way of making a login script but...

if the user name is "bob" and the password is "x10", a file exists in Accounts/ Called Bob.txt with the value "x10"

How can I make a login with that and: header("WWW-Authenticate: Basic realm=\"example\"");
 

KSclans

New Member
Messages
197
Reaction score
0
Points
0
you can use

$file=fopen("welcome.txt","r") or exit("Unable to open file!");

well if you have a html form then put a varibale or $POST_login or something like that

and I need to do some research on the value x10 one edit post later....

____
Edit:

so fopen will open your file and give permission to read that what "r" stand for Read... and use fread to display data if you only have the password or it will display all the content it have... so like

$fopen = fopen($text, 'r');
$password = fread($fopen);
and then the $password should have the password but $text need to be the file like bob.html in order to read the file...

but if you really put your password there people can just go to bob.html and see the password...I don't know why you doing it so I can't tell you exactly what you want.
 
Last edited:

mfurqanabid

New Member
Messages
37
Reaction score
0
Points
0
function runHeader(){
header('WWW-Authenticate: Basic realm="Example"');
header('HTTP/1.0 401 Unauthorized');
include("access_denied.php");
die();
}

$posFile = $_SERVER['PHP_AUTH_USER'] . ".txt";
if (file_exists("/userfile/" . $posFile)){

$file=fopen($posFile,"r");
$pass = fread($file, filesize("/userfile/" . $posFile));
fclose($file);

if ($pass!=$_SERVER['PHP_AUTH_PW']){
runHeader();
}else{
//Run Code if Valid User Here
}

}else{
runHeader();
}
Edit:
This will fulfill your need.
 
Last edited:
Top