HTTP Authorization issues
Posted: Thu Oct 05, 2006 11:10 am
Burrito | Please use
Are you still here? Well, thank you!
Burrito | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi everybody!!
Well, first thing's first I have to say hello to all people here since this is my first post, I've been getting into php during the last couple months, so I bet that I'll learn something from you all for sure. So, I just designed a very simple script trying to implement this HTTP authorization thing into my admin folder. And it works but with a very annoying problem, it pops up three times the login window and I can't figure out why. I've tried to do the same thing with an external function but keeps popping up 3 times the login window.
So, let me show you this simple piece of code and probably all you can help me out. Thanks!!Code: Select all
if (!isset($_SESSION['id_admin'])) {
header('WWW-Authenticate: Basic realm="admin"');
header('HTTP/1_0 401 Unauthorized');
$nick=$_SERVER['PHP_AUTH_USER'];
$passwd=$_SERVER['PHP_AUTH_PW'];
$sql ="SELECT nick,passwd,id_admin FROM admin WHERE nick='$nick' AND passwd='$passwd'";
$res=mysql_query($sql,$conn) or die();
$row =mysql_fetch_array($res);
if($row['nick']==$nick && $row['passwd']==$passwd){
session_start();
$_SESSION['id_admin']=$row['id_admin'];
echo "<script>document.location.href='../admin/index.php'</script>";
}else{
echo "Unauthorized\n";
}
exit();
}Burrito | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]