Ruko Posted April 25, 2010 Share Posted April 25, 2010 I followed a tutorial on making an contact form. I decided to turn it to a contact form with captcha but it gives me the following errors in the header. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ruko/public_html/JoinDevTeam.php:13) in /home/ruko/public_html/JoinDevTeam.php on line 49 Warning: Cannot modify header information - headers already sent by (output started at /home/ruko/public_html/JoinDevTeam.php:13) in /home/ruko/public_html/JoinDevTeam.php on line 81 Can someone fix this. I got the code at a tutorial. <?php { session_start(); if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) { // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here } if(isset($_POST['submit'])) if(empty($errors)) { //send the email $to = "[email protected]"; $subject="Developer Queuing"; $from = "[email protected]"; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name wants to be a developer:\n". "Name: $name\n". "Email: $visitor_email \n". "Username: $username \n". "Why he/she wants to be a developer: $devwhy \n". "Coding Knowledge: $codingknow \n". "Comments: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } ?> <div class="wrap"> <div id="bigcontent"> <div id="content"> <form method="POST" name="contact_form" action="JoinDevTeam.php"> <br /> <label for="name">Name: </label> <br /> <input type="text" name="name" value="<?php echo htmlentities($name) ?>"> <br /> <label for="email">Email: </label> <br /> <input type="text" name="email" value="<?php echo htmlentities($visitor_email) ?>"> <br /> <label for="username">Username in forums: </label> <br /> <input type="text" name="username" value="<?php echo htmlentities($username) ?>"> <br /> <label for="devwhy">Why do you want to be a developer? </label> <br /> <input type="text" name="devwhy" value="<?php echo htmlentities($devwhy) ?>"> <br /> <label for="codingknow">What do you rate yourself in PHP, HTML, and CSS coding? (out of 50): </label> <br /> <input type="text" name="codingknow" value="<?php echo htmlentities($codingknow) ?>"> <br /> <label for="excomments">Extra Comments:</label> <br /> <textarea name="excomments" rows=8 cols=30 ><?php echo htmlentities($excomments) ?></textarea> <br /> <img src="captcha.php?rand=<?php echo rand(); ?>" id="captchaimg" > <label for="excomments">Enter the code above here :</label> <input id="6_letters_code" name="6_letters_code" type="text"> <br /> <input type="submit" value="Submit" name="submit"> </form> </div></div></div></html> Quote Link to comment https://forums.phpfreaks.com/topic/199640-my-application-form-not-functioning-correctly/ Share on other sites More sharing options...
ChemicalBliss Posted April 25, 2010 Share Posted April 25, 2010 A - That cannot be the whole code since session_start is not on line 49. B - Find the sticky "HEADER ERRORS - READ HERE BEFORE POSTING THEM" On the forum this post is in. -cb- Quote Link to comment https://forums.phpfreaks.com/topic/199640-my-application-form-not-functioning-correctly/#findComment-1047855 Share on other sites More sharing options...
Ruko Posted April 25, 2010 Author Share Posted April 25, 2010 The whole code is this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Join the Development Team</title> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" /> <link rel="icon" type="image/png" href="images/favi.png" /> <link rel="stylesheet" href="style.css" type="text/css" media="screen" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js" type="text/javascript"></script> <script language="javascript"> var timeout = 500; var closetimer = 0; var ddmenuitem = 0; function jsddm_open() { jsddm_canceltimer(); jsddm_close(); ddmenuitem = $(this).find('ul').css('visibility', 'visible');} function jsddm_close() { if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');} function jsddm_timer() { closetimer = window.setTimeout(jsddm_close, timeout);} function jsddm_canceltimer() { if(closetimer) { window.clearTimeout(closetimer); closetimer = null;}} $(document).ready(function() { $('#jsddm > li').bind('mouseover', jsddm_open) $('#jsddm > li').bind('mouseout', jsddm_timer)}); document.onclick = jsddm_close; </script> </head> <? include('announcements.html') ?> <? include('logo.html') ?> <?php { session_start(); if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) { // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here } if(isset($_POST['submit'])) if(empty($errors)) { //send the email $to = "[email protected]"; $subject="Developer Queuing"; $from = "[email protected]"; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "A user $name wants to be a developer:\n". "Name: $name\n". "Email: $visitor_email \n". "Username: $username \n". "Why he/she wants to be a developer: $devwhy \n". "Coding Knowledge: $codingknow \n". "Comments: \n ". "$user_message\n". "IP: $ip\n"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; mail($to, $subject, $body,$headers); header('Location: thank-you.html'); } } ?> <div class="wrap"> <div id="bigcontent"> <div id="content"> <form method="POST" name="contact_form" action="JoinDevTeam.php"> <br /> <label for="name">Name: </label> <br /> <input type="text" name="name" value="<?php echo htmlentities($name) ?>"> <br /> <label for="email">Email: </label> <br /> <input type="text" name="email" value="<?php echo htmlentities($visitor_email) ?>"> <br /> <label for="username">Username in forums: </label> <br /> <input type="text" name="username" value="<?php echo htmlentities($username) ?>"> <br /> <label for="devwhy">Why do you want to be a developer? </label> <br /> <input type="text" name="devwhy" value="<?php echo htmlentities($devwhy) ?>"> <br /> <label for="codingknow">What do you rate yourself in PHP, HTML, and CSS coding? (out of 50): </label> <br /> <input type="text" name="codingknow" value="<?php echo htmlentities($codingknow) ?>"> <br /> <label for="excomments">Extra Comments:</label> <br /> <textarea name="excomments" rows=8 cols=30 ><?php echo htmlentities($excomments) ?></textarea> <br /> <img src="captcha.php?rand=<?php echo rand(); ?>" id="captchaimg" > <label for="excomments">Enter the code above here :</label> <input id="6_letters_code" name="6_letters_code" type="text"> <br /> <input type="submit" value="Submit" name="submit"> </form> </div></div></div></html> The main problem is the form is not working like its supposed to. Quote Link to comment https://forums.phpfreaks.com/topic/199640-my-application-form-not-functioning-correctly/#findComment-1047860 Share on other sites More sharing options...
PFMaBiSmAd Posted April 25, 2010 Share Posted April 25, 2010 Here is a summery of the sticky post that ChemicalBliss suggested that you read - You cannot output any characters on a page before a header is sent as that prevents the headers from working. Session_start() and header() both send headers. Therefore, you cannot output anything before a session_start() statement or a header() statement. You must rearrange the code on your page so that any session_start() or header() statements come before any content on your page. Content on your page is any of the following - the HTML DOCTYPE tag, css, javascript, and html. Quote Link to comment https://forums.phpfreaks.com/topic/199640-my-application-form-not-functioning-correctly/#findComment-1047867 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.