Problem in PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
chetan1
Forum Newbie
Posts: 6
Joined: Mon May 05, 2008 2:14 am

Problem in PHP?

Post 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;
}
}
yashvant
Forum Newbie
Posts: 8
Joined: Mon May 05, 2008 4:22 am

Re: Problem in PHP?

Post 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;
}
}
?>
yashvant
Forum Newbie
Posts: 8
Joined: Mon May 05, 2008 4:22 am

Re: Problem in PHP?

Post 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;
}
}
?>
DeFacto
Forum Commoner
Posts: 37
Joined: Wed Apr 23, 2008 2:30 pm

Re: Problem in PHP?

Post by DeFacto »

small notice, you should post code betwean :)
Post Reply