473,806 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

authenticate using PHP_AUTH_USER & PHP_AUTH_PW

6 New Member
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_worksh op_admin WHERE
user = '$PHP_AUTH_USER ' AND
pass = '$PHP_AUTH_PW'" ;

//put the SQL command and SQL instructions into variable
$result = mysql_query($sq l) 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 3908
rbragg
6 New Member
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
5478
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 closed and the same page is opened. I turned off all caching but still it does cache (as a refresh doen not promt again). How can I force the page to prompt for a password at every refresh ?
2
4365
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 "Basic". Can somebody help me with this? Thanks Timo
5
10895
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' && !isset($PHP_AUTH_USER) && !isset($PHP_AUTH_PW) && substr($HTTP_AUTHORIZATION, 0, 6) == 'Basic '
1
5816
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
2835
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 or any such variables. They do not show up in phpinfo() nor do they work as expected programmatically. I used to have them a few weeks ago. I have not changed any of versionned packages shown above in months.
2
4211
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 started a session, unset(session), and then destroy_session(). But, everytime I go back to the login link, It does not give me the window popup for the login information. Only when I close the brower and then try logging in does the popup window...
5
1879
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 passord and rename the file ? Should I use substring using the URI ? Pseudocode below is the best way to do so ?
3
6062
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 header 'HTTP/1.0 401 unauthorized', to force the web browser to display a username/password dialog. The script then calls exit(). I don't understand how the script gets re-invoked (after the username and password have been supplied in the...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3851
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.