Page 1 of 1

Problem in PHP?

Posted: Mon May 05, 2008 4:21 am
by chetan1
I am trying to get this php script to work for the admin section - I am following the instructions on how to add a username/password in mysql. It still doesn't work. Is there a glitch in the coding? Here it is:
<?
if (!isset ($PHP_AUTH_USER)) {
Header ("WWW-Authenticate: Basic realm=\"Administration\"");
Header ("HTTP/1.0 401 Unauthorized");
echo ("Login incorrect. Names and passwords are case sensitive.");
exit;
} else {
$user = $PHP_AUTH_USER;
$password = $PHP_AUTH_PW;
$query = "select * from admin where username = '$user' and password = '$password'";
$result = mysql_db_query("jobs", $query);
if (mysql_num_rows ( if (mysql_num_rows ($result) != 1) {
Header ("WWW-Authenticate: Basic realm=\"Administration\"");
Header ("HTTP/1.0 401 Unauthorized");
echo ("Login incorrect. Namesand passwords are case sensitive.");
exit;
}
}

Re: Problem in PHP?

Posted: Mon May 05, 2008 5:08 am
by yashvant
Hi this script working fine.
<?php
if (!isset ($PHP_AUTH_USER)) {
Header ("WWW-Authenticate: Basic realm=\"Administration\"");
Header ("HTTP/1.0 401 Unauthorized");
echo ("Login incorrect. Names and passwords are case sensitive.");
exit;
} else {
$user = $PHP_AUTH_USER;
$password = $PHP_AUTH_PW;
$query = "select * from admin where username = '$user' and password = '$password'";
$result = mysql_db_query("jobs", $query);
if (mysql_num_rows($result) != 1){
Header ("WWW-Authenticate: Basic realm=\"Administration\"");
Header ("HTTP/1.0 401 Unauthorized");
echo ("Login incorrect. Namesand passwords are case sensitive.");
exit;
}
}
?>

Re: Problem in PHP?

Posted: Mon May 05, 2008 5:50 am
by yashvant
Hi This is working and enjoy

<?php

$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
if (!isset ($PHP_AUTH_USER)) {
Header ("WWW-Authenticate: Basic realm=\"Administration\"");
Header ("HTTP/1.0 401 Unauthorized");
echo ("Login incorrect");
exit;
} else {
$user = $PHP_AUTH_USER;
$password = $PHP_AUTH_PW;
$query = "select * from admin where username = '$user' and password = '$password'";
$result = mysql_db_query("jobs", $query);
if (mysql_num_rows($result) != 1){
Header ("WWW-Authenticate: Basic realm=\"Administration\"");
Header ("HTTP/1.0 401 Unauthorized");
echo ("Login incorrect");
exit;
}
}
?>

Re: Problem in PHP?

Posted: Mon May 05, 2008 5:55 am
by DeFacto
small notice, you should post code betwean :)