I have the following code which should prompt with a pop-window for user-authentication with HTTP.
<?php
/* Program: Auth.php
* Desc: Program that prompts for a user name and
* password from the user using HTTP authentication.
* The program then tests tests whether the user
* name and password match a user name and password
* pair stored in a MySQL database.
*/
//Testing whether the user has been prompted for a user name
if(!isset($_SERVER['PHP_AUTH_USER']))
{
header('WWW-Authenticate: Basic realm="secret section"');
header('HTTP/1.0 401 Unauthorized');
exit("This page requires authentication!");
}
// Testing the user name and password entered by the user
else
{
include("Vars.inc");
$user_name = trim($_SERVER['PHP_AUTH_USER']);
$user_password = trim($_SERVER['PHP_AUTH_PW']);
$connection = mysql_connect("localhost","root","peter")
or die ("Couldn't connect to server.");
$db = mysql_select_db("UserAccount",$connection)
or die ("Couldn't select database.");
$sql = "SELECT user_name FROM Valid_User
WHERE user_name = '$user_name'
AND password = md5('$user_password')";
$result = mysql_query($sql)
or die("Couldn't execute query.");
$num = mysql_num_rows($result);
if ($num < 1) // user name/password not found
{
exit("The User Name or password you entered
is not valid.<br>");
}
}
// Web page content.
include("Welcome.inc");
?>
Unfortunately it is not presenting the pop-up window ,instead it shows in the browser a error- "The User Name or password you entered is not valid."
Whereas I have created a Vars.inc file where I have created the following code
<?php
$host = "localhost";
$user = "root";
$passwd = "peter";
$database = "UserAccount";
?>
Firstly,peter is the password for mysql prompt,root is the username, and "UserAccount" is the database created ,inside the database, I have created a "ValidUser" table and populated it with some valid data,It contains "user_name","user_password","join_date" as columns/fields with user_name being the primary key. The above program is called "auth.php" & I have placed it in this directory -
H:\xampp\htdocs\ww\Projects\Procedural\Auth.php.
I have also placed the "Vars.inc" (containing the necessary connection data) file and Welcome.inc" file inside this same folder where the above" auth.php" is located.
I am using Apache Friends XAMPP (Basis Package) version 1.7.3 ,my OS is Windows XP and I have installed not in my primary drive which is C drive ,instead my XAMPP folder is located in H:\ drive.
My php.ini is located in H:\xampp\php\php.ini & my Apache config file is located in
H:\xampp\apache\conf\httpd.conf
I have tried to modify the php.ini file by removing the ; comment symbol in front of include_path directive,but it didn't help me remove the error I am getting
Initially it was like this-
; Windows: "\path1;\path2"
;include_path = ".;c:php\includes"
But since my php.ini is not located in C drive,so I changed the above line to this-
; Windows: "\path1;\path2"
include_path = ".;H:\xampp\htdocs\ww\Projects\Procedural;H:\xampp\apache\include;"
I place all file in the above "ww" directory inside 'htdocs' folder and it used to work!!
Also I have placed duplicate copies of "Welcome.inc" and "Vars.inc" in both these folders-
1)H:\xampp\htdocs\ww\Projects\Procedural\
2)I:\data\
But still the program is not working and everytime I run the program it shows the same output - " The User Name or password you entered is not valid." !!
Earlier before this xampp package was installed ,it used to work when I fidgeted with the settings but now I dont what has happened,I can't figure it out.
Please Help
Thanks in advance