Jump to content

FORM WARNINGS


kayz100

Recommended Posts

Hi PHP FREAKS

 

I am receiving the following warning:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /homepages/my_WEB - published/contact.php:3) on line 6

 

Apart fromtis from problem everything elsem is ok on the site I am working on, please help: here is the code:

 

<?php

$your_email ='[email protected]';

 

session_start();

$errors = '';

$name = '';

$visitor_email = '';

$user_message = '';

 

if(isset($_POST['submit']))

{

 

$name = $_POST['name'];

$visitor_email = $_POST['email'];

$user_message = $_POST['message'];

if(empty($name)||empty($visitor_email))

{

$errors .= "\n Name and Email are required fields. ";

}

if(IsInjected($visitor_email))

{

$errors .= "\n Bad email value!";

}

if(empty($_SESSION['6_letters_code'] ) ||

strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)

{

 

$errors .= "\n The captcha code does not match!";

}

 

if(empty($errors))

{

$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 ".

"$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: thanks.php');

}

}

 

function IsInjected($str)

{

$injections = array('(\n+)',

'(\r+)',

'(\t+)',

'(%0A+)',

'(%0D+)',

'(%08+)',

'(%09+)'

);

$inject = join('|', $injections);

$inject = "/$inject/i";

if(preg_match($inject,$str))

{

return true;

}

else

{

return false;

}

}

?>

 

 

Kayz100

Link to comment
https://forums.phpfreaks.com/topic/274243-form-warnings/
Share on other sites

Your script is generating output prior to your call to session_start().  According to the error message, this output is being generated by the script /homepages/my_WEB - published/contact.php at line #3.

 

Headers and cookies have to be sent prior to any other script output.  Output consists of anything that would be sent to the browser, even blank lines or spaces before your opening <?php tag would be counted as output.

 

You need to figure out where the output is coming from, then re-structure your script so you call session_start() prior to that output.

Link to comment
https://forums.phpfreaks.com/topic/274243-form-warnings/#findComment-1411253
Share on other sites

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.