-1

Possible Duplicate:
Headers already sent by PHP

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\USBWebserver_v8_en\root\pages\login.php:1) in D:\USBWebserver_v8_en\root\pages\login.php on line 0

I have created a login form with html code, I have my server all set up with all the settings and all that stuff, Im using USB Webserver V8, it has the phpmyadmin feature, so i have created a database on that and used the dreamweaver to link the database fields and stuff, I then used the login validation field feature on dream weaver to m ake the page go to where ever it on on either success or failure.

When i open it up on my server i get the following errors before i even type in anything

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\USBWebserver_v8_en\root\pages\login.php:1) in D:\USBWebserver_v8_en\root\pages\login.php on line 0

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\USBWebserver_v8_en\root\pages\login.php:1) in D:\USBWebserver_v8_en\root\pages\login.php on line 0

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in D:\USBWebserver_v8_en\root\pages\login.php on line 62

when something is typed no validation occurs and i get another message as well Warning: Cannot modify header information - headers already sent by (output started at D:\USBWebserver_v8_en\root\pages\login.php:1) in D:\USBWebserver_v8_en\root\pages\login.php on line 70

This the code on my form

<form METHOD="POST" action="<?php echo $loginFormAction; ?>" id="form2">
<p>&nbsp;</p>
<p><span class="letter">Username:</span>
<input type="text"name="username""username id="username"">
</p>
<p><span class="letter">Password: </span>
<input type="password"name="password"/>
</p>
<p>
<input name="submit" type="submit" class="content1" value="Login" />
</p>
<p>&nbsp;</p>
<!-- end .content -->
</form>

and this is my php code

<?php virtual('/Connections/reuben1.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "",  $theNotDefinedValue = "") 
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}

$theValue = function_exists("mysql_real_escape_string") ?  mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;    
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
//*** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if(isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if(isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "/Pages/Home.html";
$MM_redirectLoginFailed = "/Pages/Help.html";
$MM_redirecttoReferrer = false;
mysql_select_db($database_reuben1, $reuben1);

$LoginRS__query=sprintf("SELECT username, passwowrd FROM users WHERE username=%s AND   passwowrd=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 

$LoginRS = mysql_query($LoginRS__query, $reuben1) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;       

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>

I dont have a clue as to why its not working :(

Community
  • 1
  • 1

2 Answers2

0

Look at line 1 of D:\USBWebserver_v8_en\root\pages\login.php

It is outputting something there that is stopping it starting teh session,. This could be an empty line or space before the opening php tag

Anigel
  • 3,435
  • 1
  • 17
  • 23
  • yes you were right there was another starting php tag after the starting php tag, but still i re upload the file and still nada, I was thinking could it be to do with im using usb server 8.0 when the latest is 8.5 perhaps ? – Reuben Perryman May 03 '12 at 19:39
  • @ReubenPerryman: No. Read the error message. Understand it. Fix the issue. Everything is fine then. – hakre May 03 '12 at 19:51
0
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent

What this means is that PHP has outputted some data to the browser already, meaning it can't set any headers (the things set before any HTML is sent). In this case, it usually means that there is some code before the first opening PHP tag. In login.php, make sure there is nothing before the first opening PHP tag - even whitespace (spaces, new lines, etc). The same rule applies for /Connections/reuben1.php - make sure that doesn't have any whitespace at the start of it either.

LeonardChallis
  • 7,759
  • 6
  • 45
  • 76