I am clueless as this same code earlier worked in my same machine with same XAMPP setup. Only difference is I have reinstalled XAMPP in a different drive than earlier but in both cases it was different from my primary drive,so it should work this time too but it is not working !! Earlier my XAMPP was setup in the I drive this time in the H drive ( both are external hard disks) & don't tell me to reinstall XAMPP again in my primary C partition please.
I can't remember exactly what changes i did to those configuration files in my earlier attempt but I did made some change in httpd.conf and php.ini im my earlier attempt with the following code so that it worked then, but this time I can't manage to do this again!!
I present the code below -
- Code: Select all
<?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","ABCD")
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-
- Code: Select all
<?php
$host = "localhost";
$user = "root";
$passwd = "ABCD";
$database = "UserAccount";
?>
Firstly, 'ABCD' 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:\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:\secret"
I place all php files in the above "ww" directory inside 'htdocs' folder and it used to run in browser,but this time I place the "Auth.php" inside the same ww directory and its not working.
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:\secret\
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." !!
I also created a .htaccess file in I drive where I have placed the Vars.inc & Welcome.inc files as I stated earlier.
The path for .htaccess is I:\secret\.htaccess.
I changed the "AllowOverride All" directive in the httpd.conf file to "AllowOverride AuthConfig" under <Directory "H:/xampp/htdocs"> directive.
And I also changed the 'AllowOverride All' directive within <Directory></Directory> directive just above the previous line to "AllowOverride AuthConfig" .
Is it OK or have I made some mistakes??
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