|
-
May 4th, 2003, 08:18 PM
#1
Thread Starter
Fanatic Member
HTTP authentication just doesn't work.
when I put a authentication script, a dialog box pops up and keeps asking for name/pw, ANYTHING I put (correct or wrong) it keeps asking, and after 3-4 tries it says "requires authorisation", I copied the code from php.net and from other sites, still doesnt work, do I need to "enable" this from my browser or something?
This piece of code, keeps asking me for name/pw.. even tho it doesnt even validate them.
Code:
<?php
// File Name: auth01.php
// Check to see if $PHP_AUTH_USER already contains info
if (!isset($PHP_AUTH_USER)) {
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
// If not empty, display values for variables
else {
echo "
<P>You have entered this username: $PHP_AUTH_USER<br>
You have entered this password: $PHP_AUTH_PW<br>
The authorization type is: $PHP_AUTH_TYPE</p>
";
}
?>
or this:
Code:
<?php
header("WWW-Authenticate: Basic realm=\"System Information\"");
header("HTTP/1.0 401 Unauthorized");
print $_SERVER['REMOTE_USER'];
if ( (!isset($_SERVER['$PHP_AUTH_USER'])) || (!isset($_SERVER['$PHP_AUTH_PW'])) )
{
header('WWW-Authenticate: Basic realm="Private Area"');
header("HTTP/1.1 401 Unauthorized");
print "This page requires authorisation.";
print $_SERVER['$PHP_AUTH_USER'];
print $_SERVER['$PHP_AUTH_PW'];
exit();
}
else
{
print "You're through to the secret page, was the effort worth it?";
}
?>
<html>
<head>
<title> .:Header password ****:. </title>
</head>
<body>
</body>
</html>
Last edited by scr0p; May 4th, 2003 at 08:25 PM.
asdf
-
May 5th, 2003, 01:49 PM
#2
Frenzied Member
use the second one. also it has problems as well
PHP Code:
if ( (!isset($_SERVER['$PHP_AUTH_USER'])) || (!isset($_SERVER['$PHP_AUTH_PW']))
// should be
if ( (!isset($_SERVER['PHP_AUTH_USER'])) || (!isset($_SERVER['PHP_AUTH_PW']))
//and
print $_SERVER['$PHP_AUTH_USER'];
print $_SERVER['$PHP_AUTH_PW'];
//should be
print $_SERVER['PHP_AUTH_USER'];
print $_SERVER['PHP_AUTH_PW'];
-
May 5th, 2003, 09:24 PM
#3
Thread Starter
Fanatic Member
It doesn't have to be, on my host www.team-od.com, the 2 scripts I had before the modification worked. I will try them like you said right now on my own machine.
-
May 5th, 2003, 09:25 PM
#4
Thread Starter
Fanatic Member
doesn't work.. I can write my scripts and upload to the host with no problems, the problem is somewhere on my machine.
-
May 5th, 2003, 10:04 PM
#5
Frenzied Member
Originally posted by scr0p
It doesn't have to be, on my host www.team-od.com, the 2 scripts I had before the modification worked. I will try them like you said right now on my own machine.
what do you mean? doesn't have to be??
there is no such varuiable as
$_SERVER['$PHP_AUTH_USER'];
read the manual. if you have that then you are doing it wrong.
if the problem is on your machin ethan are you running the ISAPI module? or are you in cgi mode?
-
May 6th, 2003, 06:38 PM
#6
Thread Starter
Fanatic Member
er, thats what I meant, without the $, but I meant it doesnt have to be with the $_SERVER, i can also do echo $PHP_AUTH_USER, what is the diff between CGI and ISAP? how do I check what I have installed?
-
May 6th, 2003, 07:00 PM
#7
Frenzied Member
it doesn't depend on that. it can care less if you installed it as cgi or ISAPI, it depends on the register_globals being off.
bu tall this can be found in the phpinfo();
<?php
phpinfo();
?>
add that to a page and run it. it will tell you how and what is installed with php.
this,
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
will not run in cgi mode
-
May 6th, 2003, 08:05 PM
#8
Thread Starter
Fanatic Member
-
May 6th, 2003, 09:07 PM
#9
Frenzied Member
globals ON use this $PHP_AUTH_USER
globals OFF use this $_SERVER["PHP_AUTH_USER"]
so what part doesn't work?
-
May 6th, 2003, 09:23 PM
#10
Thread Starter
Fanatic Member
When I put a authentication script, a dialog box pops up and keeps asking for name/pw, ANYTHING I put (correct or wrong) it keeps asking, and after 3-4 tries it says "requires authorisation".. Its probably a problem with something else on my PC, Apache or something, not with PHP.
-
May 6th, 2003, 09:33 PM
#11
Frenzied Member
the first piece of code should work. the second one needs to be changed to this
PHP Code:
<?php
if ( (!isset($_SERVER['$PHP_AUTH_USER'])) || (!isset($_SERVER['$PHP_AUTH_PW'])) )
{
header('WWW-Authenticate: Basic realm="Private Area"');
header("HTTP/1.1 401 Unauthorized");
print "This page requires authorisation.";
print $_SERVER['PHP_AUTH_USER'];
print $_SERVER['PHP_AUTH_PW'];
exit();
}
else
{
print "You're through to the secret page, was the effort worth it?";
}
?>
look at the difference of the two scripts. you have the "WWW-Authenticate" at the very fist of the script and it was getting asked to run everytime.
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
|