Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

login and redirect

Links for php scripts

Moderators: macek, egami, gesf

login and redirect

Postby rex » Fri Feb 28, 2003 7:09 am

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
rex
New php-forum User
New php-forum User
 
Posts: 8
Joined: Fri Feb 28, 2003 6:54 am
Location: ossett

Postby Redcircle » Sat Mar 01, 2003 1:10 am

I tested the code and it works fine.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

login and redirect

Postby rex » Sat Mar 01, 2003 1:30 am

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
rex
New php-forum User
New php-forum User
 
Posts: 8
Joined: Fri Feb 28, 2003 6:54 am
Location: ossett

Postby Redcircle » Sat Mar 01, 2003 1:39 am

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.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

login and redirect

Postby rex » Sat Mar 01, 2003 2:04 am

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
rex
New php-forum User
New php-forum User
 
Posts: 8
Joined: Fri Feb 28, 2003 6:54 am
Location: ossett

login and redirect

Postby rex » Sat Mar 01, 2003 2:18 am

sorry set username to : peter
password to : thegreek

rex
rex
New php-forum User
New php-forum User
 
Posts: 8
Joined: Fri Feb 28, 2003 6:54 am
Location: ossett

Postby Redcircle » Sat Mar 01, 2003 1:13 pm

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

What version of PHP are you running?
-
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

login and redirect

Postby rex » Sat Mar 01, 2003 1:23 pm

4 i think.
did it work for u on the link i posted earlier at clicradio?
rex
New php-forum User
New php-forum User
 
Posts: 8
Joined: Fri Feb 28, 2003 6:54 am
Location: ossett

Re: login and redirect

Postby WiZARD » Sun Mar 02, 2003 12:25 am

Hi rex!
Interesting where is you stored a password of users?
P.S. at first look script is correct :?
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

login and redirect

Postby rex » Sun Mar 02, 2003 12:32 am

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
rex
New php-forum User
New php-forum User
 
Posts: 8
Joined: Fri Feb 28, 2003 6:54 am
Location: ossett

Postby Redcircle » Mon Mar 03, 2003 12:39 am

clarification: it does not would on your site but when I copy the code and put it on my server it works fine.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

login and redirect

Postby rex » Mon Mar 03, 2003 1:44 am

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
rex
New php-forum User
New php-forum User
 
Posts: 8
Joined: Fri Feb 28, 2003 6:54 am
Location: ossett

Re: login and redirect

Postby WiZARD » Mon Mar 03, 2003 2:06 am

No i mean what if you used Auth module to you need set in .conf (apache) file in root dir of site
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

login and redirect

Postby rex » Mon Mar 03, 2003 2:15 am

sorry wizard. don't know what u mean.

rex
rex
New php-forum User
New php-forum User
 
Posts: 8
Joined: Fri Feb 28, 2003 6:54 am
Location: ossett

Re: login and redirect

Postby WiZARD » Fri Mar 07, 2003 2:53 am

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
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to PHP Scripts

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.