Forum Moderators: coopster
I cant get this this to work...
I have a form which submits to a file that check the fields and validates it and creates the Session vars.
As follows
<?php
session_start();
//create the variables
$first_name = 'first_name';
$last_name = 'last_name';
$email_address = 'email_address';
// create the session variable
$_SESSION['first_name'] = $first_name;
$_SESSION['last_name'] = $last_name;
$_SESSION['email_address'] = $email_address;
include 'db.php';
// Convert to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
if((!$username) ¦¦ (!$password)){
$error .= "Please enter ALL of the information! <br />";
include 'login_form.php';
exit();
}
// Convert password to md5 hash
$password = md5($password);
// check if the user info validates the db
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
header("Location: login_success.php");
}
} else {
$error = "You could not be logged in! Either the username and password do not match or you have not validated your membership! Please try again!<br />";
include 'login_form.html';
}
?>
if it validates it goes to the next page, login is successful
<?php
session_start();
if ( empty( $first_name) ) {
print "Please login below!";
include 'login_form.php';
}
else {
include 'db.php';
echo "Welcome, ". $_SESSION['first_name'] .". ";
echo "<title>Title</title><br><br><br><h3><b>text</b></h3>";
include 'file1.php';
echo "<br><br><br><h3><b>text:</b></h3>";
include 'file2.php';
echo "<br><br><br><h3><b>text:</b></h3>";
include 'file3.php';
echo "<br><br><br><h3><b>text:</b></h3>";
include 'file4.php';
;}
echo "<br><br><br><b><a href=logout.php>Logout</a><br>";
?>
I am getting the following error
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Inetpub\vhosts\sitename.ca\httpdocs\php\login_success.php:1) in C:\Inetpub\vhosts\sitename.ca\httpdocs\php\login_success.php on line 2
Could you look the code over... Perhaps you see something I dont.
thanks in advance
J
2 (the probable case)
there is a space b4 your 1st line if <?php in your db.php include.
.
Good luck.
J
// Convert to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
if((!$username) ¦¦ (!$password)){
$error .= "Please enter ALL of the information! <br />";
include 'login_form.php';
exit();
}
// Convert password to md5 hash
$password = md5($password);
// check if the user info validates the db
$sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
header("Location: login_success.php");
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at C:\Inetpub\vhosts\sitename.ca\httpdocs\php\login_success.php:1) in C:\Inetpub\vhosts\sitename.ca\httpdocs\php\login_success.php on line 2
This means that on line 1 of login_success.php, 'output started' already - something has been output - either a line or a space or anything else before the opening <?php tag in this file, or else something output by echo, print, or one of the other output-producing functions. The first is much more likely. Check out that file, and that line - line 1.