Jump to content

Headers already sent out?


OriginalBoy

Recommended Posts

I receive this error when I submit a form


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php:2) in /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php on line 4

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php:2) in /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php on line 7

Warning: Cannot modify header information - headers already sent by (output started at /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php:2) in /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php on line 89

Here is the code

<?php
include("config.inc.php");
session_start();
session_destroy();
include("functions.inc.php");
session_start();
$_SESSION['username'] = $_POST['username'];
$_SESSION['email'] = $_POST['email'];
$fname = clean_data($_POST['fname']);
$lname = clean_data($_POST['lname']);
$email = clean_data($_POST['email']);
$email2 = clean_data($_POST['confirmemail']);
$sq = clean_data($_POST['security']);
$sa = clean_data($_POST['security_answer']);
$work = clean_data($_POST['pwork']);
$website = clean_data($_POST['website']);
$skills1 = clean_data($_POST['skills1']);
$skills2 = clean_data($_POST['skills2']);
$skills3 = clean_data($_POST['skills3']);
$skills4 = clean_data($_POST['skills4']);
$skills5 = clean_data($_POST['skills5']);


/* data that is not checked */
$bname = clean_data($_POST['bname']);
$country = clean_data($_POST['country']);
$other = clean_data($_POST['otherskills']);
/* END data that is not checked */


$_SESSION['fname'] = $fname;
$_SESSION['lname'] = $lname;
$_SESSION['email'] = $email;
$_SESSION['secq'] = $sq;
$_SESSION['seca'] = $sa;
$_SESSION['skill'] = $skill;
$_SESSION['website'] = $website;
$_SESSION['other'] = $other;
$skill_count = 0;
if (isset($skills1) && $skills1 != ""){
$skill_count++;
}
if (isset($skills2) && $skills2 != ""){
$skill_count++;
}
if (isset($skills3) && $skills3 != ""){
$skill_count++;
}
if (isset($skills4) && $skills4 != ""){
$skill_count++;
}
if (isset($skills5) && $skills5 != ""){
$skill_count++;
}
if ($skill_count < 1){
$_SESSION['error_skill'] = true;
$_SESSION['error'] = true;
}
if (!strstr($email, "@") || !strstr($email, ".") || $email == "" || $email != $email2){
$_SESSION['error_email'] = true;
$_SESSION['error'] = true;
}
if (!(isset($fname)) || $fname == ""){
$_SESSION['error_firstname'] = true;
$_SESSION['error'] = true;
}
if (!(isset($lname)) || $lname == ""){
$_SESSION['error_lastname'] = true;
$_SESSION['error'] = true;
}
if (!(isset($sq)) || $sq == ""){
$_SESSION['error_secretq'] = true;
$_SESSION['error'] = true;
}
if (!(isset($sa)) || $sa == ""){
$_SESSION['error_secreta'] = true;
$_SESSION['error'] = true;
}
if (!(isset($skill)) || $skill == ""){
$_SESSION['error_skill'] = true;
$_SESSION['error'] = true;
}
if (!(isset($work)) || $work == ""){
$_SESSION['error_work'] = true;
$_SESSION['error'] = true;
}
if (isset($_SESSION['error']) && $_SESSION['error'] == true){
header("location:./?page=register&error=true");
}
else{
$password = encrypt($password1);
$sql = "INSERT INTO `developers` VALUES('','$fname', '$lname', '$email', '$passowrd1', '$secruity_question', '$security_answer', '$country', '$typeofskills', '$previous_work', '$image', '$website', '$company_name', '0','0');";
mysql_query($sql);
$to = $_POST['email'];
$from = "'Developers Match'<[email protected]>";
$subject = "Validate your E-Mail Address";
$sql = "SELECT * FROM `developers` WHERE `email`='$email';";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$id = $row['id'];
$key = md5(date("M-d-Y H:i:s").date("r")."fsdwe89@s".$id.$username.$email);
$sql = "INSERT INTO `verify` VALUES('$id', '$key');";
mysql_query($sql);
$message = "Thank you for regestring with Developers Match.\n\r
Please copy the link below, and paste it in your browser window:\r\n
{$main_site_url}validate.php?id=$id&key=$key\r\n
If you are unable to use this method to validate your account, you can go to\r\n
 {$main_site_url}?page=validator\r\n
 and enter the following key to activate your account:\r\n
 $key\r\n
 Thank you for registering,\r\n\r\n\r\n
 DevelopersMatch.com";
$headers = "From: $from\r\n";
mail($to, $subject, $message, $headers) or die("ERROR!");
header("location:./?page=register&register=success");
}

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/
Share on other sites

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php:2) in /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php:2) in /home1/jonsjava/public_html/developersmatch/developersmatch/p_developer.php on line 87

 

I get that error  :'(

<?php
include("config.inc.php");
session_start();
include("functions.inc.php");
$_SESSION['username'] = $_POST['username'];
$_SESSION['email'] = $_POST['email'];
$fname = clean_data($_POST['fname']);
$lname = clean_data($_POST['lname']);
$email = clean_data($_POST['email']);
$email2 = clean_data($_POST['confirmemail']);
$sq = clean_data($_POST['security']);
$sa = clean_data($_POST['security_answer']);
$work = clean_data($_POST['pwork']);
$website = clean_data($_POST['website']);
$skills1 = clean_data($_POST['skills1']);
$skills2 = clean_data($_POST['skills2']);
$skills3 = clean_data($_POST['skills3']);
$skills4 = clean_data($_POST['skills4']);
$skills5 = clean_data($_POST['skills5']);


/* data that is not checked */
$bname = clean_data($_POST['bname']);
$country = clean_data($_POST['country']);
$other = clean_data($_POST['otherskills']);
/* END data that is not checked */


$_SESSION['fname'] = $fname;
$_SESSION['lname'] = $lname;
$_SESSION['email'] = $email;
$_SESSION['secq'] = $sq;
$_SESSION['seca'] = $sa;
$_SESSION['skill'] = $skill;
$_SESSION['website'] = $website;
$_SESSION['other'] = $other;
$skill_count = 0;
if (isset($skills1) && $skills1 != ""){
$skill_count++;
}
if (isset($skills2) && $skills2 != ""){
$skill_count++;
}
if (isset($skills3) && $skills3 != ""){
$skill_count++;
}
if (isset($skills4) && $skills4 != ""){
$skill_count++;
}
if (isset($skills5) && $skills5 != ""){
$skill_count++;
}
if ($skill_count < 1){
$_SESSION['error_skill'] = true;
$_SESSION['error'] = true;
}
if (!strstr($email, "@") || !strstr($email, ".") || $email == "" || $email != $email2){
$_SESSION['error_email'] = true;
$_SESSION['error'] = true;
}
if (!(isset($fname)) || $fname == ""){
$_SESSION['error_firstname'] = true;
$_SESSION['error'] = true;
}
if (!(isset($lname)) || $lname == ""){
$_SESSION['error_lastname'] = true;
$_SESSION['error'] = true;
}
if (!(isset($sq)) || $sq == ""){
$_SESSION['error_secretq'] = true;
$_SESSION['error'] = true;
}
if (!(isset($sa)) || $sa == ""){
$_SESSION['error_secreta'] = true;
$_SESSION['error'] = true;
}
if (!(isset($skill)) || $skill == ""){
$_SESSION['error_skill'] = true;
$_SESSION['error'] = true;
}
if (!(isset($work)) || $work == ""){
$_SESSION['error_work'] = true;
$_SESSION['error'] = true;
}
if (isset($_SESSION['error']) && $_SESSION['error'] == true){
header("location:./?page=register&error=true");
}
else{
$password = encrypt($password1);
$sql = "INSERT INTO `developers` VALUES('','$fname', '$lname', '$email', '$passowrd1', '$secruity_question', '$security_answer', '$country', '$typeofskills', '$previous_work', '$image', '$website', '$company_name', '0','0');";
mysql_query($sql);
$to = $_POST['email'];
$from = "'Developers Match'<[email protected]>";
$subject = "Validate your E-Mail Address";
$sql = "SELECT * FROM `developers` WHERE `email`='$email';";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$id = $row['id'];
$key = md5(date("M-d-Y H:i:s").date("r")."fsdwe89@s".$id.$username.$email);
$sql = "INSERT INTO `verify` VALUES('$id', '$key');";
mysql_query($sql);
$message = "Thank you for regestring with Developers Match.\n\r
Please copy the link below, and paste it in your browser window:\r\n
{$main_site_url}validate.php?id=$id&key=$key\r\n
If you are unable to use this method to validate your account, you can go to\r\n
 {$main_site_url}?page=validator\r\n
 and enter the following key to activate your account:\r\n
 $key\r\n
 Thank you for registering,\r\n\r\n\r\n
 DevelopersMatch.com";
$headers = "From: $from\r\n";
mail($to, $subject, $message, $headers) or die("ERROR!");
header("location:./?page=register&register=success");
}

?>

<?php
function encrypt($data){
$enc_data = md5($data."X5ouZtsKES7h");
return $enc_data;
}
function clean_data($data){
$data = mysql_real_escape_string($data);
$data = strip_tags($data);
return $data;
}

function userLevel(){
return $_SESSION['user_level'];
}
function box2(){
if (login(true, false, false)){
	print "<a href='?page=logout'>Logout</a>";
	if(isAdmin()){
		print "<a href='?page=see_all_users'>View All Developers</a>";;
	}
}
else{
	/* Login box */
	print "<a href='?page=login'>Login</a>";
	echo<<<END


END;
}
}
function login($check_login=false, $username=false, $password=false){
if ($username != false && $password != false && $check_login != true){
	$sql = "SELECT * FROM `developers` WHERE `email`='$username' AND `password`='$password' AND `valid`=1;";
	$result = mysql_query($sql);
	$total_found = mysql_num_rows($result);
	if ($total_found < 1){
		return false;
	}
	else{
		$row = mysql_fetch_assoc($result);
		$_SESSION['username'] = $row['email'];
		$_SESSION['user_level'] = $row['user_level'];
		$_SESSION['user_id'] = $row['id'];
		$_SESSION['is_valid'] = true;
		return true;
	}
}
elseif ($check_login == true && $_SESSION['is_valid'] == true && isset($_SESSION['username'])){
	return true;
}
else{
	return false;
}
}

function logout(){
session_unset();
session_destroy();
header("location:?");
exit();
}

function getTopSites($limit){
$sql = "SELECT * FROM `developers` ORDER BY `id` DESC LIMIT $limit";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
	$site_image = $row['image'];
	$site_url = $row['website'];
	$site_title = $row['company_name'];
	$id = $row['id'];
	$owner_id = $row['owner_id'];
	$count_comments = countComments($id);
	print "<p><a href='./?page=site_info&id=$id'><p>$site_title </a>    $count_comments Comments(<a href='./?page=comment&id=$id'>Add</a>)</p></p>";
}
}


function viewSelectedSite($id, $new_tab=true){
$sql = "SELECT * FROM `developers` WHERE `id`='$id' LIMIT 1;";

}
function countComments($id){
$sql = "SELECT * FROM `comments` WHERE `site_id`='$id' ORDER BY `id` DESC;";
$result = mysql_query($sql);
$number = mysql_num_rows($result);
return $number;
}

function getSelectedSiteComments($id){
$sql = "SELECT * FROM `comments` WHERE `site_id`='$id' ORDER BY `id` DESC;";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
	$name = $row['name'];
	$datetime = $row['datetime'];
	$subject = $row['subject'];
	$message = $row['comment'];
	$message = str_replace("\\", "", $message);
	$subject = str_replace("\\", "", $subject);
	if ($url != ""){
		$name_url = "<a href='$url' target='_blank'>$name</a>";
	}
	else{
		$name_url = $name;
	}
	$comment = $row['comment'];
	echo<<<END
	<table border="0" width="100%">
<tr>
	<td><h3>$name_url</h3></td>
	<td align="right">$datetime</td>
</tr>
</table>
<table border="0">
<tr>
	<td><h3>$subject</h3></td>
</tr>
</table>
<table border="0">
<tr>
	<td>$message</td>
</tr>
</table>
<br /><br />
<hr width='50%' size='7' align='left' noshade>
END;
}
print "<br /><br /><br /><br /><hr width='100%' size='7' align='left' noshade>";
}

function addComment($id, $name, $url, $comment){
/* We don't allow URLs in their comments */
if (strstr($comment, "a href") || strstr($comment, "img src")){
	return false;
}
else{
	$comment = strip_tags($comment);
	$sql = "INSERT INTO `comments` VALUES('','$id','$name','$email','$comment');";
	mysql_query($sql);
	return true;
}
}

function getAdvertisement($type, $limit="none"){
if (is_numeric($limit)){
	$sql = "SELECT * FROM `advertisement` WHERE `type`='$type' ORDER BY RAND() LIMIT $limit;";
}
else{
	$sql = "SELECT * FROM `advertisement` WHERE `type`='$type' ORDER BY RAND() LIMIT 1;";
}
$result = mysql_query($sql);
$number = mysql_num_rows($result) or 0;
if ($number != 0){
	$row = mysql_fetch_assoc($result) or "empty";
	$url = $row['url'];
	$img = $row['img_url'];
	$ad = "<p><a href=\"$url\" target=\"_BLANK\"><img class='addy' src=\"$img\" border=\"0\"></a></p><br />";
}
else{
	$ad = "";
}

return $ad;
}
function isAdmin(){
if ($_SESSION['user_level'] == "3"){
	return true;
}
else{
	return false;
}
}

Also, this code at line 87 wont work

 

header("location:./?page=register&register=success");

 

 

You've already sent output to the browser.  Use a HTML or Javascript redirect.

 

Nah, the output is from PHP sending out the error from the session.  The header() redirect should be fine after the sessions are sorted out.

Also, this code at line 87 wont work

 

header("location:./?page=register&register=success");

 

 

You've already sent output to the browser.  Use a HTML or Javascript redirect.

actually, there isn't any data outputted at that point.

so, with that said:

 

<?php
session_start();
session_unset();
include("config.inc.php");
include("functions.inc.php");
$_SESSION['username'] = $_POST['username'];
$_SESSION['email'] = $_POST['email'];
$fname = clean_data($_POST['fname']);
$lname = clean_data($_POST['lname']);
$email = clean_data($_POST['email']);
$email2 = clean_data($_POST['confirmemail']);
$sq = clean_data($_POST['security']);
$sa = clean_data($_POST['security_answer']);
$work = clean_data($_POST['pwork']);
$website = clean_data($_POST['website']);
$skills1 = clean_data($_POST['skills1']);
$skills2 = clean_data($_POST['skills2']);
$skills3 = clean_data($_POST['skills3']);
$skills4 = clean_data($_POST['skills4']);
$skills5 = clean_data($_POST['skills5']);


/* data that is not checked */
$bname = clean_data($_POST['bname']);
$country = clean_data($_POST['country']);
$other = clean_data($_POST['otherskills']);
/* END data that is not checked */


$_SESSION['fname'] = $fname;
$_SESSION['lname'] = $lname;
$_SESSION['email'] = $email;
$_SESSION['secq'] = $sq;
$_SESSION['seca'] = $sa;
$_SESSION['skill'] = $skill;
$_SESSION['website'] = $website;
$_SESSION['other'] = $other;
$skill_count = 0;
if (isset($skills1) && $skills1 != ""){
   $skill_count++;
}
if (isset($skills2) && $skills2 != ""){
   $skill_count++;
}
if (isset($skills3) && $skills3 != ""){
   $skill_count++;
}
if (isset($skills4) && $skills4 != ""){
   $skill_count++;
}
if (isset($skills5) && $skills5 != ""){
   $skill_count++;
}
if ($skill_count < 1){
   $_SESSION['error_skill'] = true;
   $_SESSION['error'] = true;
}
if (!strstr($email, "@") || !strstr($email, ".") || $email == "" || $email != $email2){
   $_SESSION['error_email'] = true;
   $_SESSION['error'] = true;
}
if (!(isset($fname)) || $fname == ""){
   $_SESSION['error_firstname'] = true;
   $_SESSION['error'] = true;
}
if (!(isset($lname)) || $lname == ""){
   $_SESSION['error_lastname'] = true;
   $_SESSION['error'] = true;
}
if (!(isset($sq)) || $sq == ""){
   $_SESSION['error_secretq'] = true;
   $_SESSION['error'] = true;
}
if (!(isset($sa)) || $sa == ""){
   $_SESSION['error_secreta'] = true;
   $_SESSION['error'] = true;
}
if (!(isset($skill)) || $skill == ""){
   $_SESSION['error_skill'] = true;
   $_SESSION['error'] = true;
}
if (!(isset($work)) || $work == ""){
   $_SESSION['error_work'] = true;
   $_SESSION['error'] = true;
}
if (isset($_SESSION['error']) && $_SESSION['error'] == true){
   header("location:./?page=register&error=true");
}
else{
   $password = encrypt($password1);
   $sql = "INSERT INTO `developers` VALUES('','$fname', '$lname', '$email', '$passowrd1', '$secruity_question', '$security_answer', '$country', '$typeofskills', '$previous_work', '$image', '$website', '$company_name', '0','0');";
   mysql_query($sql);
   $to = $_POST['email'];
   $from = "'Developers Match'<[email protected]>";
   $subject = "Validate your E-Mail Address";
   $sql = "SELECT * FROM `developers` WHERE `email`='$email';";
   $result = mysql_query($sql);
   $row = mysql_fetch_assoc($result);
   $id = $row['id'];
   $key = md5(date("M-d-Y H:i:s").date("r")."fsdwe89@s".$id.$username.$email);
   $sql = "INSERT INTO `verify` VALUES('$id', '$key');";
   mysql_query($sql);
   $message = "Thank you for regestring with Developers Match.\n\r
   Please copy the link below, and paste it in your browser window:\r\n
   {$main_site_url}validate.php?id=$id&key=$key\r\n
   If you are unable to use this method to validate your account, you can go to\r\n
    {$main_site_url}?page=validator\r\n
    and enter the following key to activate your account:\r\n
    $key\r\n
    Thank you for registering,\r\n\r\n\r\n
    DevelopersMatch.com";
   $headers = "From: $from\r\n";
   mail($to, $subject, $message, $headers) or die("ERROR!");
   header("location:./?page=register&register=success");
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.