Click to See Complete Forum and Search --> : PHP authentication


Nehalem
07-04-2002, 03:35 PM
I really need to buy a linux book or something since I keep getting stuck on one thing after another. Here is my basic problem:
I want to set up athentication on my site. I wasn't going to use apache authentication because I don't have the right module installed to do so ( I have redhat 7.3 installed as webserver). So I figured I would just use PHP which has been working just fine. So I follow the tutorials out there and have used the following code as given by the PHP manual:
<?php
if (!isset($PHP_AUTH_USER)) {
header("WWW-Authenticate: Basic realm=\"My Realm\"");
header("HTTP/1.0 401 Unauthorized");
echo "Text to send if user hits Cancel button\n";
exit;
} else {
echo "<p>Hello $PHP_AUTH_USER.</p>";
echo "<p>You entered $PHP_AUTH_PW as your password.</p>";
}
?>
I think I don't have the CGI version installed but rather the module but I can't say I am totally sure. As for the results of the snippet of code I get the dialog box wanting my user name and stuff but whenever I put anything in and click ok it just returns the dialog box so I can't go anywhere (the cancel button works however). I have tried different variations of this code but it does the same thing. Is this what PHP does if I don't have the module. I thought I might have the module because all the code seems present in httpd.conf and I thought I installed it as a module but if their is a way to check let me know. Also would it be better just to try install the apache server again and use it's authentication. The thing that confuses me about Linux coming from windows is that I worry about there being conflicts in my system since I would install apache all over again and wouldn't have a clue how to remove my old version. Is all that matters is which copy of the server you have running as a process? If so that scares me because every tutorial out there talks about initd.conf rather than xinetd (?) so I don't get how to make startup processes in redhat yet either.
So drop me a line. Give me some advice (or recommed a good book or two). Maybe none of the ways I have considered is the best way. I don't know but I could use some help. I look forward to when I can acutally be dishing out the advice someday but until then I'll have to write these essays :). Thanks!

manual_overide
07-09-2002, 01:03 AM
easiest way to do that is to use a cookie and redirection:

<?php
if ($user == "whoever" && $pass == "thepassword")
{
setcookie("LoggedIn", "yes");
}

header("Location: login.php");
?>


then login.php would look something like:

<?php
if ($LoggedIn == "yes")
{
<your content>
}
else
{
<some login form>
}
?>



I did the same thing at http://www.ucband.uc.edu/sections/brass/tubas/login.php
the username is "tubas" and the pass is "win" if you care to check it out.