•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 361,873 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,391 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3263 | Replies: 2
![]() |
•
•
Join Date: Jun 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hello. I have installed PHP4 and MySQL (.dmg) on Mac OSX v3 client. Everything is up and running. I have created tables in my DB, established user privileges, etc through the 'terminal' app. I have turned on web sharing through the 'preferences' panel and dragged my .php files to the 'sites' folder.
Accessing localhost/127.0.0.1 I see the .php files - simple scipts work.
The problem is connecting to my DB and being able to execute a simple query on any of my tables. Below is an authentication script I found. I want to match username/password entries. Unfortunately I cannot even establish a connection to my DB, the $PHP_AUTH_USER AND _PW don't seem to do anything and I keep getting the 401 error. What can I do to get at my tables? (I apologize about the long email, but if anyone has some advice please let me know) Do the .dmg files set up PHP as a standalone/cgi instead of an apache module?
-----
<?php
$auth = false; // Assume user is not authenticated
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
// Connect to MySQL
mysql_connect( 'hostname', 'username', 'password' )
or die ( 'Unable to connect to server.' );
// Select database on MySQL server
mysql_select_db( 'your_db' )
or die ( 'Unable to select database.' );
// Formulate the query
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else {
echo '<P>You are authorized!</P>';
}
?>
html >>
<form action='post' methos="xxx.php"
<input type="text" name="username" value="" />
<input type="password" name="password" value="" />
.....submit button
</form>
Accessing localhost/127.0.0.1 I see the .php files - simple scipts work.
The problem is connecting to my DB and being able to execute a simple query on any of my tables. Below is an authentication script I found. I want to match username/password entries. Unfortunately I cannot even establish a connection to my DB, the $PHP_AUTH_USER AND _PW don't seem to do anything and I keep getting the 401 error. What can I do to get at my tables? (I apologize about the long email, but if anyone has some advice please let me know) Do the .dmg files set up PHP as a standalone/cgi instead of an apache module?
-----
<?php
$auth = false; // Assume user is not authenticated
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
// Connect to MySQL
mysql_connect( 'hostname', 'username', 'password' )
or die ( 'Unable to connect to server.' );
// Select database on MySQL server
mysql_select_db( 'your_db' )
or die ( 'Unable to select database.' );
// Formulate the query
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query( $sql )
or die ( 'Unable to execute query.' );
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else {
echo '<P>You are authorized!</P>';
}
?>
html >>
<form action='post' methos="xxx.php"
<input type="text" name="username" value="" />
<input type="password" name="password" value="" />
.....submit button
</form>
•
•
Join Date: Feb 2003
Location: London, England
Posts: 281
Reputation:
Rep Power: 7
Solved Threads: 6
Try replacing $PHP_AUTH_USER and $PHP_AUTH_PW with $_SERVER['PHP_AUTH_USER'] and $_SERVER['PHP_AUTH_PW'] respectively.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
apple blog bugs codeweavers companies competition computing core crossover daniweb defcon emulation gentoo hackers hacks hate hoax iphone jbennet kevin rose leopard linux mac macs microsoft news office os os x osx parallels pc php pro processor secret security serunson spam tiger trojan unix virtualization vista vmware vulnerabilities web wifi windows wine
- free php/mysql programming (Web Development Job Offers)
- SMS Message With PHP/MYSQL (PHP)
- PHP-MySQL Conn Problem in Win XP (PHP)
- PHP and MySQL Web Development (PHP)
- php mysql help (PHP)
- Using PHP, MySQL and Apache Server (PHP)
Other Threads in the PHP Forum
- Previous Thread: Auction Site
- Next Thread: PHP Sessions on IIS


Linear Mode