473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

authenticate using PHP_AUTH_USER & PHP_AUTH_PW

6
In my db, I have the fields user and pass with one record.

With the following code, I get a continuous dialog box display. If I put in a bogus user/pass OR the correct user or pass, the dialog box pops up again.

<?php

//assume user is not authenticated
$auth = false;

$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];

if ( isset($user) && isset($pass) )

{
//connect to db
include 'db_connect.php';

//SQL query to find if this entered username/password is in the db
$sql = "SELECT * FROM healthed_workshop_admin WHERE
user = '$PHP_AUTH_USER' AND
pass = '$PHP_AUTH_PW'";

//put the SQL command and SQL instructions into variable
$result = mysql_query($sql) or die('Unable to connect.');


//get number or rows in command; if more than 0, row is found
$num_matches = mysql_num_rows($result);

if ($num_matches !=0)
{
//matching row found authenticates user
$auth = true;
}
}

if (!$auth)
{
header('WWW-Authenticate: Basic realm="Health Ed Presentation Admin"');
header('HTTP/1.0 401 Unauthorized');
echo 'You must enter a valid username & password.';
exit;
}
else
{
echo 'Success!';
}
?>
Jul 31 '06 #1
1 3883
rbragg
6
Nevermind. My problem was here:

user = '$PHP_AUTH_USER' AND
pass = '$PHP_AUTH_PW'";

This needed to be:

user = '$user' AND
pass = '$pass";

... since I had already defined these variables. ;)
Jul 31 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: thenetflyer | last post by:
<!-- The following sample should authorize the user to log on the site. This works once but after refreshing the browser, it does not prompt again for login until all browser (IE 6) windows are...
2
by: Timo Steinbach | last post by:
Hi, I use basic authentication in Apache. I like to use the global variable $_SERVER. Unfortunately this variable is empty/no availabe. Same with PHP_AUTH_PW. AUTH_TYPE is working and states...
5
by: BT3 | last post by:
(newbie) I have taken some code directly out of a book: <?php // if we are using IIS, we need to set $PHP_AUTH_USER and $PHP_AUTH_PW if (substr($SERVER_SOFTWARE, 0, 9) == 'Microsoft' &&...
1
by: jerrygarciuh | last post by:
Hello, I am finding that on a new server where I am developing $_SERVER and $_SERVER Do not show up in $_SERVER when I when they should be defined I test using print_r($_SERVER) or this
3
by: Bernard Higonnet | last post by:
I'm running Apache/2.0.52 (Unix) mod_perl/1.99_16 Perl/v5.8.5 PHP/5.0.1 under FreeBSD 4.11-RELEASE #0. I suddenly (sic) no longer have PHP_AUTH_USER, PHP_AUTH_PW, and AUTH_TYPE or REMOTE_USER...
2
by: gsherp | last post by:
How do I unset PHP_AUTH_USER and PHP_AUTH_PW? I am trying to create a logout script and I am encountering a problem where when go to relogin, I am already logged in. In my logout script, I...
5
by: Bob Bedford | last post by:
Hi all, I've to accept a file that is sent using a POST method. The file will be sent using this URL: http://username:pass@www.mysite.com/upload.php How can I retrieve the username and...
3
by: kurtk | last post by:
I had a question about the use of the HTTP header 'WWW-Authenticate' in PHP scripts. For example, the script below sends the header 'WWW- Authenticate: Basic Realm="Secret Stash"', followed by the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.