Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Authenticating a username and password
I've just learnt the basics of PHP and am now moving on to connecting to MySQL databases and the like. What I am going to do is to validate a username and pass against an entry in a database. However I can't even get the login box and headers to show up on the page. I simply get a parse error. I am using Linux and Apache as a server + PHP4. (LAMP).Please can anyone help? Many thanks.
These are the error messages which I recieve:
Warning: Cannot modify header information - headers already sent by (output started at /srv/www/htdocs/php/members_only.php:11) in /srv/www/htdocs/php/members_only.php on line 18
Warning: Cannot modify header information - headers already sent by (output started at /srv/www/htdocs/php/members_only.php:11) in /srv/www/htdocs/php/members_only.php on line 19
Here is my code (it is simplified - it leaves out DB connections and simply tries to get the user to login).
This is a simple page which authenticates a password and username
if($_POST['action'] == 'submitted')
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
header('HTTP/1.0 401 Unauthorized');
header('WWW-Authenticate: Basic realm="My Realm"');
echo 'You are not logged in';
echo "<p>Hello $user.";
You entered $pass as your password.