Jump to content

prob while 'header' in php


believeinsharing

Recommended Posts

I am trying to add captcha to my contact us form....

I did that but I do have prob while validating captcha.

 

As i know captcha validation should be on server side.

my code is:

 


<?php

session_start();

$captcha=$_SESSION['captcha_code'];

$ecaptcha=$_POST['code'];

echo "actual captcha :".$captcha ."</br>";

echo "entered captcha:".$ecaptcha;

$_SESSION['captchaError']==false;

if ($ecaptcha==$captcha)

{

 

echo "right captcha entered";

}

else

{

$_SESSION['captchaError']==true;

echo "wrong captcha entered";

        header('Location:contactus.php') ;

}

 

 

?>


 

because, I m using  header('Location:contactus.php') it showing contactus.php directly without error msg;

 

is their any other way to do this?

thanks in advance

Link to comment
Share on other sites

Right, the page is not displayed until processing completed and you are redirecting the user to a different page before processing completes. But, since you are already storing the captcha error in session data you can simply use that on the contactus.php page to display the error.

Link to comment
Share on other sites

@Psycho:

thx for reply, I am going that my contactus.php form has following code:


if ($_SESSION['captchaError']==true)

{

echo "<p id='contErrorMsg' style='display: none;color:red;'>Please fill the required fields</p>";

}

?>


and i m setting $_SESSION['captchaError'] value in send.php file

when contactus page will reload it will check $_SESSION['captchaError'] value n base on tht will display or not above <p>

 

my que is is their any way to check that page is loading first time or second time.

 

Thanks in advance

Link to comment
Share on other sites

my que is is their any way to check that page is loading first time or second time.

 

Sure, you could store a session value each time that page is loaded. But, I'm not really understanding what you are REALLY trying to achieve. I think the issue you are having is that when loading contactus.php you don't know if the error was a previous error or a new error. If that is the case, then check for the error as you do now - then remove the error.

if ($_SESSION['captchaError']==true)
{
    echo "<p id='contErrorMsg' style='display: none;color:red;'>Please fill the required fields</p>";
    $_SESSION['captchaError'] = false;
} 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.