Welcome to WebmasterWorld Guest from 107.22.7.35

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Captcha session failing in PHP

     
4:35 pm on Apr 11, 2012 (gmt 0)

5+ Year Member



we have been using this code to run CAPTCHA on a web-based contact form, but there is a fail in it somewhere - can anyone see an obvious error?

Here is the error message:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/galaxyin/public_html/templates/layer.php:5) in /home/galaxyin/public_html/pages/contact.php on line 2

this is the code:

<?php
session_start();
$envio = $_GET['sent'];
$contactname = $_POST['contactname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$txtCaptcha = $_POST['txtCaptcha'];
if ($envio==1)
{
$msg="";
// check the name
if(!$contactname=$_POST['contactname']) {$msg.="<span class='info'>Please enter your name</span><br>";}

// check and validate email
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email ))
{$msg.="<span class='info'>Please enter a valid email address</span><br>";}

if(!$phone=$_POST['phone']) {$msg.="<span class='info'>Please enter your phone</span><br>";}

if(!$message=$_POST['message']) {$msg.="<span class='info'>Please enter your message</span><br>";}

if ( ($_REQUEST["txtCaptcha"] == $_SESSION["security_code"]) &&
(!empty($_REQUEST["txtCaptcha"]) && !empty($_SESSION["security_code"])) ){}
else
{$msg.="<span class='info'>Please enter correct CAPTCHA!</span><br>"; }

if (!$msg)
{

// send admin email
$aem="Name: ".$contactname."\n";
$aem.="Email: ".$email."\n";
$aem.="Phone: ".$phone."\n";
$aem.="Message: ".$message."\n";
mail("", "[] Query! (".$contactname.")", $aem, "From:");
}
echo $msg;
}
?>
Here is the code:
4:42 pm on Apr 11, 2012 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member




headers already sent (output started at /home/galaxyin/public_html/templates/layer.php:5) in /home/galaxyin/public_html/pages/contact.php on line 2


This tells you where to look. If I had to guess, I would guess that layer.php has whitespace before the opening php tag. Otherwise, you are echoing something to the browser before starting the session. There can be no output before the session_start function.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month