Hi All

I am trying to create a login page using php and mysql database.

This is the code that I am trying to use:
<?php
// File Name: auth04.php
// Check to see if $PHP_AUTH_USER already contains info

if (!isset($PHP_AUTH_USER)) {
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
exit;

} else if (isset($PHP_AUTH_USER)) {
// If non-empty, check the database for matches
// connect to MySQL

mysql_connect("localhost", "mysql", "sunny")
or die ("Unable to connect to database.");

// select database on MySQL server

mysql_select_db("masterstream")
or die ("Unable to select database.");

// Formulate the query

$sql = "SELECT *
FROM guest
WHERE login='$PHP_AUTH_USER' and password='$PHP_AUTH_PW'";

// Execute the query and put results in $result
$result = mysql_query($sql);

// Get number of rows in $result. 0 if invalid, 1 if valid.

$num = mysql_numrows($result);

if ($num != "0") {
echo "<P>You're authorized!</p>";
exit;

} else {

header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
}
?>

This is the error that I get when I point my browser to this page both when the script is run locally and on th eremte webserver.
btw: I am running Mac OS Jagaur

Warning: Cannot add header information - headers already sent by (output started at /Users/pgarcha/Sites/auth.php:7) in /Users/pgarcha/Sites/auth.php on line 13

Warning: Cannot add header information - headers already sent by (output started at /Users/pgarcha/Sites/auth.php:7) in /Users/pgarcha/Sites/auth.php on line 14


Many Thanks
--Pushpinder



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to