OriginalBoy Posted October 6, 2008 Share Posted October 6, 2008 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®ister=success"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/ Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 Did you even read your code? You call session_start(), then immediately you call session_destroy(), then you call session_start() yet again. Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658325 Share on other sites More sharing options...
trecool999 Posted October 6, 2008 Share Posted October 6, 2008 Why are you starting a session, then destroying it and starting it again? Why not just use session_unset? Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658330 Share on other sites More sharing options...
genericnumber1 Posted October 6, 2008 Share Posted October 6, 2008 do you have any line breaks above the <?php in the file? and as he said, your code is.. messy Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658332 Share on other sites More sharing options...
OriginalBoy Posted October 6, 2008 Author Share Posted October 6, 2008 I got it made for me by a friend I don't know anything about sessions Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658380 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 It appears that your friend doesn't either. Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658388 Share on other sites More sharing options...
OriginalBoy Posted October 6, 2008 Author Share Posted October 6, 2008 He does he just did it in a rush or maybe I put it together wrong.... Can someone help me fix this? Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658390 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 He does he just did it in a rush or maybe I put it together wrong.... Can someone help me fix this? We already told you. Remove every session_* function in there, and just put ONE session_start() ABOVE the first include. Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658407 Share on other sites More sharing options...
OriginalBoy Posted October 6, 2008 Author Share Posted October 6, 2008 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 :'( Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658422 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 Can I see your new code? That second error will go away when the first one's fixed, btw. Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658425 Share on other sites More sharing options...
OriginalBoy Posted October 6, 2008 Author Share Posted October 6, 2008 <?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®ister=success"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658431 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 functions.inc.php might be trying to start a session. Can I please see the contents of functions.inc.php? Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658433 Share on other sites More sharing options...
OriginalBoy Posted October 6, 2008 Author Share Posted October 6, 2008 <?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; } } Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658439 Share on other sites More sharing options...
revraz Posted October 6, 2008 Share Posted October 6, 2008 Put session_start(); as your first line of code. Then read the error and see what it's telling you for where output was started. Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658440 Share on other sites More sharing options...
revraz Posted October 6, 2008 Share Posted October 6, 2008 Also, this code at line 87 wont work header("location:./?page=register®ister=success"); You've already sent output to the browser. Use a HTML or Javascript redirect. Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658441 Share on other sites More sharing options...
DarkWater Posted October 6, 2008 Share Posted October 6, 2008 Also, this code at line 87 wont work header("location:./?page=register®ister=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. Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-658447 Share on other sites More sharing options...
jonsjava Posted October 7, 2008 Share Posted October 7, 2008 Also, this code at line 87 wont work header("location:./?page=register®ister=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®ister=success"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/127292-headers-already-sent-out/#findComment-659066 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.