believeinsharing Posted August 1, 2012 Share Posted August 1, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/266551-prob-while-header-in-php/ Share on other sites More sharing options...
Psycho Posted August 1, 2012 Share Posted August 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266551-prob-while-header-in-php/#findComment-1365992 Share on other sites More sharing options...
believeinsharing Posted August 1, 2012 Author Share Posted August 1, 2012 @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 Quote Link to comment https://forums.phpfreaks.com/topic/266551-prob-while-header-in-php/#findComment-1366009 Share on other sites More sharing options...
Psycho Posted August 1, 2012 Share Posted August 1, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/266551-prob-while-header-in-php/#findComment-1366074 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.