I'm looking for a little help with a password protection script I am trying to install on an admin area of a website.
I get this error message....
Warning: Cannot send session cookie - headers already sent by (output started at /home/ccooper/smallvolcano-www/admin/index.php:6) in /home/ccooper/smallvolcano-www/admin/user_auth_test.php on line 6
When I try to install an included php page with my authentication code.
I would like to add this file to the top of each page within the admin area to verify all users against a database.
Here is my authentication code which is in a file called user_auth_test.php
<?php
include("conf.php");
include("common.php");
session_start();
if(!isset($uid))
{ ?>
<html>
<head>
<title> Please Log In for Access </title>
</head> <body>
<h1> Login Required </h1>
<p>You must log in to access this area of the site.
<p><form method="post" action="<?=$PHP_SELF?>">
User ID: <input type="text" name="name" size="8"><br>
Password: <input type="password" name="password" SIZE="8"><br>
<input type="submit" value="Log in"></form>
</body>
</html>
<?php exit;}
session_register("name");
session_register("password");
dbConnect("sessions");$sql = "SELECT * FROM user WHERE name = '$name' AND password = PASSWORD('$password')";
$result = mysql_query($sql);if (!$result) { error("A database error occurred while checking your ". "login details.\nIf this error persists, please ". "contact kevin@sitepoint.com.");}
if (mysql_num_rows($result) == 0)
{ session_unregister("name"); session_unregister("password"); ?>
<html>
<head>
<title> Access Denied </title>
</head> <body> <h1> Access Denied </h1>
<p>Your user ID or password is incorrect, or you are not a registered user on this site.
</body>
</html>
<?php
exit;}
?>
And here is the code for my index.php page of my admin area.
<link rel="stylesheet" href="main.css" type="text/css">
<body bgcolor="#000000">
<table cellpadding="0" cellspacing="0" border="0" width="780" align="center">
<tr>
<td>
<?
// includes
include("user_auth_test.php");
?>
<?
// includes
include("site_nav.php");
?>
</td>
</tr>
</table>
</body>
The site_nav.php is just a file that has the navigation for the administration area.
Any help on this is greatly appreciated.