View Full Version : Cannot send session cache limiter - headers already sent

Demon Templates
03-06-2010, 09:24 PM
HI all, I have a bit of a head ache with a small bit of php that is driving me nuts.

Iím doing a bit of work for someone and the contact form is out putting an error. This is the URL (http://www.pembrokeshirewebsolutions.co.uk/test2/index.php)

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home1/pembrok1/public_html/pws.co.uk/test2/index.php:7) in /home1/pembrok1/public_html/pws.co.uk/test2/html-contact-form.php on line 4

However, html-contact-form.php reads like this

$your_email ='iknowthis@hotmail.com';// <<=== update to your email address

$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';


$name = $_POST['name'];
$visitor_email = $_POST['email'];
$user_message = $_POST['message'];
///------------Do Validations-------------
$errors .= "\n Name and Email are required fields. ";
$errors .= "\n Bad email value!";
if(empty($_SESSION['6_letters_code'] ) ||
strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";

//send the email
$to = $your_email;
$subject="New form submission";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';

$body = "A user $name submitted the contact form:\n".
"Name: $name\n".
"Email: $visitor_email \n".
"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');

// Function to validate against any email injection attempts
function IsInjected($str)
$injections = array('(\n+)',
$inject = join('|', $injections);
$inject = "/$inject/i";
return true;
return false;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<title>Contact Us</title>
<!-- define some style elements-->
label,a, body
font-family : Arial, Helvetica, sans-serif;
font-size : 12px;
font-family : Verdana, Helvetica, sans-serif;
font-size : 12px;
color: red;
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>

echo "<p class='err'>".nl2br($errors)."</p>";
<div id='contact_form_errorloc' class='err'></div>
<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label for='name'>Name: </label><br>
<input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
<label for='email'>Email: </label><br>
<input type="text" name="email" value='<?php echo htmlentities($visitor_email) ?>'>
<label for='message'>Message:</label> <br>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Enter the code above here :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Can't read the image? click <a href='javascript: refreshCaptcha();'>here</a> to refresh</small>
<input type="submit" value="Submit" name='submit'>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator = new Validator("contact_form");
//remove the following two lines if you like error message box popups

frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address");
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
var img = document.images['captchaimg'];
img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
Code from the <a href='http://www.html-form-guide.com/contact-form/html-contact-form-captcha.html'
>php contact form</a> article.

Anyone have some suggestions?

Thanks in advance

03-06-2010, 09:35 PM
At the top of the index.php file (not the one you're working in now) put <?php ob_start(); ?> before any other content or code.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum