I'm trying to make a member system using sessions;
I've got a login page, posting to a validation script, redirecting to the members area. The code is below; Could someone please tell me why i get these errors?
"Warning: Cannot send session cookie - headers already sent by (output started at /home/sites/site226/web/00826-37286/validate.php:6) in /home/sites/site226/web/00826-37286/validate.php on line 36
Warning: Cannot send session cache limiter - headers already sent (output started at /home/sites/site226/web/00826-37286/validate.php:6) in /home/sites/site226/web/00826-37286/validate.php on line 36
Warning: Cannot add header information - headers already sent by (output started at /home/sites/site226/web/00826-37286/validate.php:6) in /home/sites/site226/web/00826-37286/validate.php on line 38"
Validate Page:
Code: Select all
<html>
<head>
<title>validate page</title>
</head>
<body>
<?php
#------------------------------------------------------------------------------
#*** CHANGE THESE PARAMETERS TO USE YOUR OWN DATABASE AND USERNAME/PASSWORD ***
$Databasename = '**********';
$DBUsername = '**********';
$DBPassword = '**********';
$Hostname = 'localhost';
#------------------------------------------------------------------------------
$user_name = $_POSTї'user_name'];
$password = $_POSTї'password'];
//connect to the DB and select the database
$connection = mysql_connect($Hostname, $DBUsername, $DBPassword) or die(mysql_error());
mysql_select_db($Databasename, $connection) or die(mysql_error());
//set up the query
$query = "SELECT * FROM Users
WHERE user_name='$user_name' AND password='$password'";
//run the query and get the number of affected rows
$result = mysql_query($query, $connection) or die('error making query');
$affected_rows = mysql_num_rows($result);
//if there's exactly one result, the user is validated.
// Otherwise, he's invalid
if($affected_rows == 1) {
$redirect_uri = "http://www.mysite.com/00826-37286/loggedin.php";
//add the user to our session variables
session_start();
$_SESSIONї'username'] = $user_name;
Header ("Location: $redirect_uri");
}
else {
echo '<font face="Verdana" color=Red size=2>Password Not Valid<br><br><br><a
href="http://www.MYSITE.com/00826-37286/home.php?id=9">Click Here To Return To The Login
Screen</a></font>';
}
?>
</body>
</html>"Warning: Cannot send session cookie - headers already sent by (output started at /home/sites/site226/web/00826-37286/loggedin.php:2) in /home/sites/site226/web/00826-37286/loggedin.php on line 3
Warning: Cannot send session cache limiter - headers already sent (output started at /home/sites/site226/web/00826-37286/loggedin.php:2) in /home/sites/site226/web/00826-37286/loggedin.php on line 3"
Code: Select all
<html>
<?
session_start();
if(empty($_SESSIONї'username'])) {
die('An error has ocurred. It may be that you have not logged in, or that your session has expired.
Please try <a href="http://www.MYSITE.com/00826-37286/home.php?id=9">logging in</a> again or contact the
<a href="mailto:Admin@MYSITE.com">system administrator</a>');
}
extract($HTTP_GET_VARS);
if (!$id) $id = 1;
switch($id) {
case 1:
include('member/topframe.php');
include('member/main.php');
include('member/botframe.php');
break;
case 2:
include('member/topframe.php');
include('member/cp.php');
include('member/botframe.php');
break;
case 3:
include('member/topframe.php');
include('member/logout.php');
include('member/botframe.php');
break;
default:
include('member/topframe.php');
include('member/main.php');
include('member/botframe.php');
}
?>
</html>Thanks
Rob