login and redirect

A

Anonymous

Guest
help please.
i'm wanting to have a login page on a site that will depending on the login details send a user to a particular secure page e.g. user001 sent to page001.htm, user002 sent to page002.htm etc.
someone wrote this for me but it doesn't seem to work anywhere i've tried it (different servers etc). it asks for the password 3 times then sends user straight to the 'Access Denied!' page every time.
i'm completely new to php having come from a design background.
-------------------------------------------------
<?php



// If user isn't authenticated
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic Realm="please login"');
header('HTTP/1.0 401 Unathorized');
echo "<h1>Access Denied!</h1>\n";
exit;
} else {
switch($_SERVER['PHP_AUTH_USER']) {
case 'admin': // Is username is admin
if ($_SERVER['PHP_AUTH_PW'] == 'admin') {
header("Location: http://www.yahoo.com/");
exit;
} else {
echo "Auth failed!\n";
}
break;

case 'user':
if ($_SERVER['PHP_AUTH_PW'] == 'password') {
header("Location: http://www.google.com/");
exit;
} else {
echo "Auth failed!\n";
}
break;

case 'peter':
if ($_SERVER['PHP_AUTH_PW'] == 'thegreek') {
header("Location: http://www.bbc.co.uk/");
} else {
echo "Auth failed!\n";
}
break;

default:
break;
}
}
?>

-------------------------------------------------

hope someone can help
thanks

rex
 
thanks for that.

any idea why i can't get it going. tried it on zeus webserver and apache. just get the same thing each time. is it something i'm doing wrong or could it be the server (as you can probably tell, i don't know much about this).
permissions seem to be fine and i can run other php scripts from the same place, guestbooks etc.

thanks

rex
 
there is one problem. in your switch statement you should have 'access failed' echoed in your default statement.. otherwise it goes to a blank page if the usename isn't listed in the script.
 
hello again redcircle,

tried that and still seem to get the same. if you'd like to see, it's at

http://www.clicradio.co.uk/guestbook/login.php

thanks

rex
 
sorry set username to : peter
password to : thegreek

rex
 
don't know what's up.. it worked fine for me.

What version of PHP are you running?
-
 
4 i think.
did it work for u on the link i posted earlier at clicradio?
 
Hi rex!
Interesting where is you stored a password of users?
P.S. at first look script is correct :?
 
at the moment the passwords are hard coded into the script. i'd like to draw them from a flat file at a lter date. just want to get this working first.
have u tried it at

http://www.clicradio.co.uk/guestbook/login.php

with user : peter
password : thgreek

rex
 
clarification: it does not would on your site but when I copy the code and put it on my server it works fine.
 
so is it the server or something i'm doing wrong? i've checked with the administrator and PHP and perl are both installed.
also other PHP scripts such as guestbooks seem to work.

thanks
rex
 
No i mean what if you used Auth module to you need set in .conf (apache) file in root dir of site
 
I mean what you may configure .htaccess in root of your www_root....
You may use htpasswd.exe for create passwd file like in Unix/Linux system and place in this root too....
It's call like APACHE_AUTH
Actually about that it's the best way if you want make Authorization system without MySQL :wink:
Read manual about it in manual of Apache
 
Back
Top