Getting Error On Page - Help Needed

Discussion in 'HTML & Website Design' started by Gynew, Jul 8, 2008.

  1. #1
    I'm not exactly sure what is going wrong, but I'm a bit of a part time web designer/marketer who is doing a bit of work for my dad to help out with his business.

    Anyway I setup somewhat of a landing page to drive Google AdWords traffic to in the hope of generating some more leads but at the bottom this error has been coming up:

    http://www.forkforce.com/used-forklifts-for-sale.php

    Can anyone please let me know what is going wrong... and how I can fix it. Thanks.
     
    Gynew, Jul 8, 2008 IP
  2. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #2
    Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/ew1102/public_html/used-forklifts-for-sale.php:71) in /home/ew1102/public_html/contformheader.inc.php on line 32


    The error message says it all - you are using session_start() after you have written something to web page (probably a print or echo statement). Session cookies have to be used before you draw the page.
     
    itcn, Jul 9, 2008 IP
  3. Gynew

    Gynew Member

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    I'll be honest and say that what you just said is way over my head. I just tried copying and pasting the code from my dad's contact page into this one, but it seems to have gone pair shaped... and I don't know what to change to fix it, will it help if I post the source code of the various pages here?
     
    Gynew, Jul 10, 2008 IP
  4. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #4
    Yes, it certainly will - post and it and we'll see what is causing the error.
     
    itcn, Jul 10, 2008 IP
  5. Gynew

    Gynew Member

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    This is the contact form code that I have put on the landing page:

    <style type="text/css" media="screen"><!--
    @import url('contform.css');
    --></style>
    
    
    <form method="post" action=""><!-- action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" -->
    <div class="contform" style="float: left; margin: 0px 20px; _margin-right: -6px;">
    	<p style="font-size: 14px; font-weight: bold; margin-top: 10px;">Contact Details:</p>
    	<label for="name">Name:*</label>
    		<input type="text" name="name" value="<?php echo $form['name']; ?>" class="text" />
    	<label for="company">Company:</label>
    		<input type="text" name="company" value="<?php echo $form['company']; ?>" class="text" />
    	<label for="address">Address:</label>
    		<input type="text" name="address" value="<?php echo $form['address']; ?>" class="text" />
    	<label for="state">State:</label>
    		<input type="text" name="state" value="<?php echo $form['state']; ?>" class="text" />
    	<label for="email">Email:*</label>
    		<input type="text" name="email" size="28" value="<?php echo $form['email']; ?>" class="text" />
    	<label for="phone">Phone No.:</label>
    		<input type="text" name="phone" value="<?php echo $form['phone']; ?>" class="text" />
    	<div class="clear"></div>
    
    <p style="font-size: 14px; font-weight: bold; margin-top: 10px;">Product Information:</p>
    	<label for="request_type"><input type="radio" name="request_type" value="Sales"<? if($form['request_type'] == 'Sales'){ echo " checked"; } ?> /> Sales</label>
    	<label for="request_type"><input type="radio" name="request_type" value="Service"<? if($form['request_type'] == 'Service'){ echo " checked"; } ?> /> Service</label>
    	<label for="request_type"><input type="radio" name="request_type" value="Hire"<? if($form['request_type'] == 'Hire'){ echo " checked"; } ?> /> Hire</label>
    	<div class="clear"></div>
    
    <label for="make">Make:</label>
    		<select class="text" name="make">
    			<option value="any">Any</option>
    							<option value="TOYOTA">TOYOTA</option>
    
    								<option value="T.C.M">T.C.M</option>
    								<option value="MITSUBISHI">MITSUBISHI</option>
    								<option value="NISSAN">NISSAN</option>
    								<option value="YALE">YALE</option>
    								<option value="KOMATSU">KOMATSU</option>
    								<option value="CROWN">CROWN</option>
    
    								<option value="HYSTER">HYSTER</option>
    								<option value="CLARK">CLARK</option>
    								<option value="LANSING">LANSING</option>
    								<option value="HAKO">HAKO</option>
    								<option value="MOFFET">MOFFET</option>
    								<option value="LINDE">LINDE</option>
    
    								<option value="EUROLIFTER">EUROLIFTER</option>
    								<option value="NICHIYU">NICHIYU</option>
    								<option value="JUNGHEINRICH">JUNGHEINRICH</option>
    								<option value="MIC">MIC</option>
    								<option value="BIG JOE">BIG JOE</option>
    								<option value="DAEWOO">DAEWOO</option>
    
    								<option value="MANITOU">MANITOU</option>
    								<option value="NYK">NYK</option>
    								<option value="CATERPILLAR">CATERPILLAR</option>
    								<option value="SUMITOMO">SUMITOMO</option>
    								<option value="DATSUN">DATSUN</option>
    								<option value="PRAMAC">PRAMAC</option>
    
    						</select>
    	
    	<div class="clear"></div>
    	<div align="left"><label for="additional_info">Additional Info:*</label><textarea name="additional_info" rows=5 class="text"><?php echo $form['additional_info']; ?>- lift height 
    - lift capacity, 
    - model
    - term of hire
    - etc</textarea>
    	</div>
    	<div class="clear"></div>
    	<div class="left"><p style="font-size:10px;">* Denotes required fields</p><input type="submit" name="submit" value="Submit Enquiry" class="button" /></div>
    </div>
    </form>
    
    
    PHP:


    This is the conform.inc.php file:

    <style type="text/css" media="screen"><!--
    @import url('contform.css');
    --></style>
    <h2>Enquiry</h2>
    <p>* Denotes required fields</p>
    <form method="post" action=""><!-- action="<?php echo basename($_SERVER["PHP_SELF"]); ?>" -->
    <div class="contform" style="float: left; margin: 0px 20px; _margin-right: -6px;">
    	<p style="font-size: 16px; margin-top: 10px;">Contact Details</p>
    	<label for="name">Name:*</label>
    		<input type="text" name="name" value="<?php echo $form['name']; ?>" class="text" />
    	<label for="company">Company:</label>
    		<input type="text" name="company" value="<?php echo $form['company']; ?>" class="text" />
    	<label for="address">Address:</label>
    		<input type="text" name="address" value="<?php echo $form['address']; ?>" class="text" />
    	<label for="state">State:</label>
    		<input type="text" name="state" value="<?php echo $form['state']; ?>" class="text" />
    	<label for="postcode">Postcode:</label>
    		<input type="text" name="postcode" value="<?php echo $form['postcode']; ?>" class="text" />
    	<label for="email">Email:*</label>
    		<input type="text" name="email" size="28" value="<?php echo $form['email']; ?>" class="text" />
    	<label for="phone">Phone No.:</label>
    		<input type="text" name="phone" value="<?php echo $form['phone']; ?>" class="text" />
    	<label for="fax">Fax:</label>
    		<input type="text" name="fax" value="<?php echo $form['fax']; ?>" class="text" />
    <div class="clear"></div>
    <p style="font-size: 16px; margin-top: 10px;">Product Information</p>
    	<label for="request_type"><input type="radio" name="request_type" value="Sales"<? if($form['request_type'] == 'Sales'){ echo " checked"; } ?> /> Sales</label>
    	<label for="request_type"><input type="radio" name="request_type" value="Service"<? if($form['request_type'] == 'Service'){ echo " checked"; } ?> /> Service</label>
    	<label for="request_type"><input type="radio" name="request_type" value="Hire"<? if($form['request_type'] == 'Hire'){ echo " checked"; } ?> /> Hire</label>
    	<div class="clear"></div>
    	<label for="lift_height">Lift Height:</label>
    		<input type="text" name="lift_height" value="<?php echo $form['lift_height']; ?>" class="text" />
    	<label for="lift_capacity">Lift Capacity:</label>
    		<input type="text" name="lift_capacity" value="<?php echo $form['lift_capacity']; ?>" class="text" />
    	<label for="make">Make:</label>
    		<select class="text" name="make">
    			<option value="any">Any</option>
    			<?
    			$res = mysql_query("SELECT * FROM brand",$db);
    			while($row = mysql_fetch_array($res)){
    				?>
    				<option value="<?= $row['brand']; ?>"<? if($form['make'] == $row['brandid']){ echo " selected"; } ?>><?= $row['brand']; ?></option>
    				<?
    				}
    			?>
    		</select>
    	<label for="model">Model:</label>
    		<input type="text" name="model" value="<?php echo $form['model']; ?>" class="text" />
    	<label for="type">Type:</label>
    		<input type="text" name="type" value="<?php echo $form['type']; ?>" class="text" />
    	<label for="term_of_hire">Term of Hire:<br /><span class="small">(Hire only)</span></label>
    		<input type="text" name="term_of_hire" value="<?php echo $form['term_of_hire']; ?>" class="text" />
    	<div class="clear"></div>
    	<div align="left"><label for="additional_info">Additional Info:*</label><textarea name="additional_info" rows=5 class="text"><?php echo $form['additional_info']; ?></textarea>
    	</div>
    	<div class="clear"></div>
    	<div class="left"><input type="submit" name="submit" value="Submit Enquiry" class="button" /></div>
    </div>
    </form>
    PHP:


    This is the contformheader.inc.php file:

    <?php
    /**
     * Clears header field to avoid injection
     * <a href="http://www.anders.com/projects/sysadmin/formPostHijacking/
    " title="http://www.anders.com/projects/sysadmin/formPostHijacking/
    ">http://www.anders.com/projects/sysadmin/formPostHijacking/
    </a> * <a href="http://www.davidseah.com/archives/2005/09/01/wp-contact-form-spam-attack/
    " title="http://www.davidseah.com/archives/2005/09/01/wp-contact-form-spam-attack/
    ">http://www.davidseah.com/archives/2005/09/01/wp-contact-form-spam-attack...</a> */
    function preprocessHeaderField($value)
    {
      //Remove line feeds
      $ret = str_replace("\r", "", $value);
      $ret = str_replace("\n", "", $ret);
    
      // Remove injected headers
      $find = array("/bcc\:/i", 
                    "/Content\-Type\:/i", 
                    "/Mime\-Type\:/i", 
                    "/cc\:/i", 
                    "/to\:/i");
      $ret = preg_replace($find, 
                          "**bogus header removed**",
                          $ret);
    
      return $ret;
    }
    
    
    define('TO_ADDRESS','marketing@forkforce.com');
    if(!$_SESSION){
    	session_start();
    	}
    if(isset($_POST["submit"])){
    	$form = $_POST;
    	unset($_POST);
    	if(array_key_exists("submit",$form)){
    		unset($form['submit']);
    		}
    	if(!eregi("^([[:alnum:]]|_|\.|-)+@([[:alnum:]]|\.|-)+(\.)([a-z]{2,4})$", $form['email'])){
    		$note = "Please enter a valid email address";
    		}
    	elseif ($form['name'] == '' || (strstr($form['name'], "bcc:")) || $form['additional_info'] == ''){ 
    		$note = "Please enter all required fields" ;
    		}
    	else{
    		$to      = TO_ADDRESS;
    		$subject = "Website Enquiry";
    		$message =	"-- Start Email --
    					<br />
    					<br />
    					<table>";
    		$bProblem = false;
    		foreach($form as $key => $value){
    
    			$message .= "<tr>
    							<th width=150 align='left' valign='top'> ".ucwords(str_replace("_"," ",$key)).": </th>
    							<td> ".$value." </td> 
    						</tr>";
    						
    			if (strstr($key, "bcc:")) {
    				$bProblem = true;
    			}
    		}
    		$message .=	"</table>
    					<br />
    					<br />
    					-- End Email --";
    		
    
    		#$to = "carl.magno@eworld.com.au";
    
    		$message = preprocessHeaderField($message);
    		$tName = preprocessHeaderField($form['name']);
    		if (strstr($form['name'], "bcc") or (strstr($tName, "bogus")) or (strstr($message, "bogus"))) {
    				$bProblem = true;
    				//echo("TRUE");
    		}
    			
    		if ($bProblem):
    			$headers =	"From: Website Enquiry <".$form['email'].">\r\n".
    						"Reply-To: Return Website <".$form['email'].">\r\n";
    			$xheaders = "X-Mailer: PHP/" . phpversion()."\r\n".
    						"Content-Type:text/html; charset=\"iso-8859-1\"";
    			//mail($to, "ERROR", $message, $headers.$xheaders);		
    			$note = "Your message was NOT sent (invalid characters) !";	
    		else:
    			$headers =	"From: ".$subject." <".$form['email'].">\r\n".
    						"Reply-To: ".$form['name']." <".$form['email'].">\r\n";
    			$xheaders = "X-Mailer: PHP/" . phpversion()."\r\n".
    						"Content-Type:text/html; charset=\"iso-8859-1\"";
    			mail($to, $subject, $message, $headers.$xheaders);			
    			$note = "Your message was sent !";
    		endif;
    
    		
    		}
    	}
    ?>
    PHP:
     
    Gynew, Jul 10, 2008 IP
  6. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #6
    remove these 3 lines:

    if(!$_SESSION){
    session_start();
    }

    from around line 31 in contformheader.inc.php
     
    itcn, Jul 11, 2008 IP
  7. Gynew

    Gynew Member

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Thank you so much! You are a god send!

    I don't suppose I could ask one more question... as it stands after the submission it just refreshes the page, is there a way to set the contact form up so that once someone submits their enquiry that it then redirects to a thank you page.
     
    Gynew, Jul 14, 2008 IP
  8. Gynew

    Gynew Member

    Messages:
    89
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    Sorry about bumping this thread back up but I was wondering if anyone knew how to make it so the "phone" field of the submission form was compulsory?
     
    Gynew, Jul 24, 2008 IP
  9. IGiveMoney

    IGiveMoney Peon

    Messages:
    116
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    you will need to do something like

    if(isset($_POST['Submit'])){
    header('Location:thankyou.php');
    }

    Basically that checks if the submit has been done, if it has then it will go to thankyou.php

    But you have to find the proper placement for it. I havent looked at your code, but if you
    are doing something else first - that would have to come after it.

    Hope it helps a little
     
    IGiveMoney, Jul 24, 2008 IP