0

I have the following code that checks for captcha validation in php. If successful it will echo correct etc.

<?
/*
	This is the back-end PHP file for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial
	
	You may use this code in your own projects as long as this 
	copyright is left in place.  All code is provided AS-IS.
	This code is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	For the rest of the code visit http://www.WebCheatSheet.com
	
	Copyright 2006 WebCheatSheet.com	
*/

//Continue the session
session_start();

//Make sure that the input come from a posted form. Otherwise quit immediately
if ($_SERVER["REQUEST_METHOD"] <> "POST")
 die("You can only reach this page by posting from the html form");

//Check if the securidy code and the session value are not blank
//and if the input text matches the stored text
if ( ($_REQUEST["txtCaptcha"] == $_SESSION["security_code"]) &&
     //txtCaptcha is on frmCaptcha and LogMeIn.php
    (!empty($_REQUEST["txtCaptcha"]) && !empty($_SESSION["security_code"])) ) {
  echo "<h1>Test successful!</h1>";
//LOAD index.html here....
} else {
  echo "<h1>Test failed! Try again!</h1>";
}
?>

It works fine, although I have tried a million way to load my index.html page after true validation.

Any ideas?

2
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by AndreRet
0

I have the following code that checks for captcha validation in php. If successful it will echo correct etc.

<?
/*
	This is the back-end PHP file for the How to Create CAPTCHA Protection using PHP and AJAX Tutorial
	
	You may use this code in your own projects as long as this 
	copyright is left in place.  All code is provided AS-IS.
	This code is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	For the rest of the code visit http://www.WebCheatSheet.com
	
	Copyright 2006 WebCheatSheet.com	
*/

//Continue the session
session_start();

//Make sure that the input come from a posted form. Otherwise quit immediately
if ($_SERVER["REQUEST_METHOD"] <> "POST")
 die("You can only reach this page by posting from the html form");

//Check if the securidy code and the session value are not blank
//and if the input text matches the stored text
if ( ($_REQUEST["txtCaptcha"] == $_SESSION["security_code"]) &&
     //txtCaptcha is on frmCaptcha and LogMeIn.php
    (!empty($_REQUEST["txtCaptcha"]) && !empty($_SESSION["security_code"])) ) {
  echo "<h1>Test successful!</h1>";
//LOAD index.html here....
} else {
  echo "<h1>Test failed! Try again!</h1>";
}
?>

It works fine, although I have tried a million way to load my index.html page after true validation.

Any ideas?

Is it displaying the "test successful" message? If it isn't echoing "test successful" message, then there is something wrong with the validation. If it does display the message, then the validation works. As for going back to index.html, just put

header("location:index.html");

on line 29.

0

Yes, it shows successful, the problem is with the header part becuase the page has already "loaded and can not call header anymore, as per other threads. I'm fairly new to php, css etc. but I have tried your solution. I have also tried the OnClick in the button itself, no luck.

Can it be because it is reading from another php page all validations?

0

When I have used "header", it loads the index page on teh same page as the LOgin screen, below all controls....:)

0

It says header can't be sent because the code is below the page header. You can't open header after you close it. Instead of header, try:

<meta http-equiv="refresh" content="0;url=index.html" />
0

Thanks guys. I have almost forgotten about this post. I have managed to solve this by using -

<a href = ""</a>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.