Forum Moderators: coopster

Message Too Old, No Replies

Absolute Beginner on PHP - Set up

         

itsdanny

1:21 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



I've installed PHP and MYSQL and it appears to be working onto my XP Pro/IIS 5 machine (well PHPInfo.php delivers what i think it should as well as conenct to the DB). I am reworking a site to be done in PHP. I am starting at the admin secition of the site and attempting to create the login page, however the errors i am getting are

Notice: Undefined variable: PHP_AUTH_USER in c:\inetpub\wwwroot\gsssecure\index.php on line 17

Notice: Undefined variable: PHP_AUTH_PW in c:\inetpub\wwwroot\gsssecure\index.php on line 18

And below is the script (the lines it refers to are bold)

<?

$auth = false; //asumes not authenticated

if (!isset ($PHP_AUTH_USER) &&!isset($PHP_AUTH_PW)) {

// connect to mysql
mysql_connect('localhost','rootuser','rootadmin')
or die ('Unable to connect at this time to the server');

// select the DB table
mysql_select_db('DATABASE')
or die ('Unable to find the database you requested');

// create the query
$sql = "Select * from USERS where
[b]username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";[/b]

// execute query
$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
$auth = true;
}
}

if (! $auth) {
header('WWW-Authenticate: Basic realm="Private"');
header('HTTP/1.0 401 Unauthorised');
echo 'Authorisation Required';
exit;
} else {
echo "<p>You are now logged in </p>";
}
?>

Now, i've read on the net that i may need to configure IIS to use ISAPI filters (i only installed the .exe without any altering any other settings) is this true?
Any tips or sugestions most helpful at this stage.
Thanks
Dan

willis1480

1:26 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



I dont think your are using globals correctly. GO here:

[us2.php.net...]

itsdanny

2:58 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



Sorted got it working (via the manual instalation) the script challenges the user but i don't think it's working properly with the DB (though that's more to do with the script) so more work required ASAP, me thinks.
cheers
Dan

coopster

3:22 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, itsdanny.

The last couple of paragraphs on the HTTP authentication with PHP [php.net] page shed some light on IIS/ISAPI usage as well.

itsdanny

10:24 am on Nov 11, 2004 (gmt 0)

10+ Year Member



The problem is, when the user gets challenged the login box is looking to log me into the domain name of my company example.co.uk (though even my username and password) rather than localhost and into the mysql database/website i'm building. Are there some settings i need to configure somewhere? Hope this makes sense to someone...
thanks
Dan

[edited by: coopster at 11:41 am (utc) on Nov. 11, 2004]
[edit reason] no urls as per TOS [webmasterworld.com] [/edit]

coopster

11:50 am on Nov 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I would assume that the link you are using is pointed to that site, that's why the authentication is coming from the site's server.

itsdanny

10:32 am on Nov 12, 2004 (gmt 0)

10+ Year Member



Well, the user gets challenged as soon as the page loads, within localhost. There is nothing anywhere whithin the site to link it to my company.co.uk website/network site. So I think the LAN could be playing a role in this. I've not attempted this on my stand alone laptop so who knows really?