Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
WWW-Authenticate user/pass checked against mysql database
Old 08-25-2004, 03:02 AM WWW-Authenticate user/pass checked against mysql database
jake5253's Avatar
Average Talker

Posts: 27
Location: Pennsylvania, USA
Trades: 0
Hi.

I've come to the decision I'm horrible with php/mysql together...

I'm trying to get a "WWW-Authenticate" dialog to check the entered username and password against those stored in a mysql database. The Authenticate dialog works properly and such, but i'm having a hell of a time trying to get mysql and this dialog to work together (if they even will?)

PHP Code:
<?php
if ($_SERVER['PHP_AUTH_USER'] != "user" || $_SERVER['PHP_AUTH_PW'] != "password")
{
    
header('WWW-Authenticate: Basic realm="Restricted Area"');
    
header('HTTP/1.0 401 Unauthorized');
    
    echo 
"You must log in to access this page.";
    
    exit;
}
?> 

//page content will load here if entered user and password is correct
Obviously, "user" needs to be checked against "user" in the database, and "password" needs to be checked against the "password" for the corresponding "user" in the database.


Thanks!!
~Jake
jake5253 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-25-2004, 03:10 AM
Christopher's Avatar
Iced Cap

Latest Blog Post:
Cross-domain AJAX with JSONP
Posts: 3,110
Location: Toronto, Ontario
Trades: 0
PHP Code:
<?php

$res 
mysql_query("SELECT * FROM table WHERE user='" $_SERVER['PHP_AUTH_USER'] . "' AND pass='"$_SERVER['PHP_AUTH_PW'] . "'");

if(
mysql_num_rows($res) < 1)
{
    
header('WWW-Authenticate: Basic realm="Restricted Area"');
    
header('HTTP/1.0 401 Unauthorized');
    echo 
"You must log in to access this page.";
    exit; 
}
Of course, adding slashes to the user and password to prevent SQL injection and whatnot.
__________________

Please login or register to view this content. Registration is FREE
- Latest Articles:
Please login or register to view this content. Registration is FREE
,
Please login or register to view this content. Registration is FREE

--
Please login or register to view this content. Registration is FREE

Christopher is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to WWW-Authenticate user/pass checked against mysql database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.48053 seconds with 12 queries