Jump to content

CAPTCHA & redirect


JPark

Recommended Posts

I am trying to set up a mathematical CAPTCHA script and having a problem.  I can get it to work to a point.  In the following code, at the <form action>, if I give no URL (action=""), I can get the script to return a success or failure.  However, I want the form to go to another page upon a success (instead of just getting a successful message).  When I put in a URL in the form action

( <form action="success.htm"> ), I will go to the new page even if the CAPTCHA answer is wrong.

 

What do I do??

 

Thanks!

<?php
// Start up your PHP session. The captcha does not work without this enabled.
session_start();
// Check if the form has been submitted.
if(isset($_POST['example_submit']))
{
// The form has been submitted, so let's check if the captcha has been entered correctly.
if($_POST['example_captcha'] == $_SESSION['main_captcha'])
{
	// It worked! If you want to process other types of form information, this is where you will do it.
	// I just simply print the value of the name text box out onto the screen here.
	echo('<b>Correct!</b>');
}
else
{
	// Oh no, they got it wrong, so we'll tell them to try it again.
	echo('<b>Sorry.  That is incorrect.  Please try again.</b>');
}
}

// Here, we've included the actual captcha function. You can change the name to whatever you'd like.
function main_captcha()
{
// First of all we are going to set up an array with the text equivalents of all the numbers we will be using.
$captcha_number_convert = array(0=>'zero', 1=>'one', 2=>'two', 3=>'three', 4=>'four', 5=>'five', 6=>'six', 7=>'seven', 8=>'eight', 9=>'nine', 10=>'ten');
// Choose the first number randomly between 6 and 10. This is to stop the answer being negative.
$captcha_number_first = mt_rand(6, 10);
// Choose the second number randomly between 0 and 5.
$captcha_number_second = mt_rand(0, 5);
// Set up an array with the operators that we want to use. At this stage it is only subtraction and addition.
$captcha_operator_convert = array(0=>'+', 1=>'-');
// Choose the operator randomly from the array.
$captcha_operator = $captcha_operator_convert[mt_rand(0, 1)];
// Get the equation in textual form to show to the user.
$captcha_return = (mt_rand(0, 1) == 1 ? $captcha_number_convert[$captcha_number_first] : $captcha_number_first) . ' ' . $captcha_operator . ' ' . (mt_rand(0, 1) == 1 ? $captcha_number_convert[$captcha_number_second] : $captcha_number_second);
// Evaluate the equation and get the result.
eval('$captcha_result = ' . $captcha_number_first . ' ' . $captcha_operator . ' ' . $captcha_number_second . ';');
// Store the result in a session key.
$_SESSION['main_captcha'] = $captcha_result;
// Return the question along with a bit of text in front as it will be used in the form itself.
return 'What is the answer to ' . $captcha_return . '?';
}
?>

<form action="success.htm" method="post">
<table>
<tr>
<td>
<label for=""><?php echo(main_captcha()); ?></label>
</td>
<td>
<input id="example_captcha" type="text" name="example_captcha" />
</td>
</tr>
<tr>
<td colspan="2" align="">
<input type="submit"  name="example_submit" value="Test The Captcha!" />
</td>
</tr>
</table>
</form>

Link to comment
Share on other sites

???

// Check if the form has been submitted.
if(isset($_POST['example_submit']))
{
// The form has been submitted, so let's check if the captcha has been entered correctly.
if($_POST['example_captcha'] == $_SESSION['main_captcha'])
{
	// It worked! If you want to process other types of form information, this is where you will do it.
	// I just simply print the value of the name text box out onto the screen here.
	header("Location: http://www.mywebsite.com/success.htm");
}
else
{
	// Oh no, they got it wrong, so we'll tell them to try it again.
	echo('<b>Sorry.  That is incorrect.  Please try again.</b>');
}
}

 

Doesn't work...

Link to comment
Share on other sites

If the CAPTCHA answer is wrong, I get the error message, "Sorry.  That is incorrect.  Please try again."

 

If the CAPTCHA answer is correct, I don't go anywhere.  I thought I would go to success.htm but I don't.  The form just reloads.

Link to comment
Share on other sites

you have error_reporting turned on? if not, put this @ the top of your script: error_reporting(E_ALL);

 

run the script again, see if any errors come up.

 

and do you have a mod_rewrite on .htm files? otherwise, upon submission of the form, the file success.htm will be processed as that is the file being requested via action in the form.

 

'cause when you leave that blank, ie. action="", you are telling the form to submit the current working page which is why you are getting success and failure values returned.

Link to comment
Share on other sites

This the error I get:

Warning: Cannot modify header information - headers already sent by (output started at /homepages/1/d245573826/htdocs/notifyme/testing/almostdone.php:8) in /homepages/1/d245573826/htdocs/notifyme/testing/almostdone.php on line 521

 

What's odd is that I can get this to work on a much simpler form:

<?php
// Start up your PHP session. The captcha does not work without this enabled.
session_start();
// Check if the form has been submitted.
if(isset($_POST['example_submit']))
{
// The form has been submitted, so let's check if the captcha has been entered correctly.
if($_POST['example_captcha'] == $_SESSION['main_captcha'])
{
	// It worked! If you want to process other types of form information, this is where you will do it.
	// I just simply print the value of the name text box out onto the screen here.
	header("Location: success.php");

}
else
{
	// Oh no, they got it wrong, so we'll tell them to try it again.
	echo('I\'m sorry. That is incorrect.  Please try again.');
}
}

// Here, we've included the actual captcha function. You can change the name to whatever you'd like.
function main_captcha()
{
// First of all we are going to set up an array with the text equivalents of all the numbers we will be using.
$captcha_number_convert = array(0=>'zero', 1=>'one', 2=>'two', 3=>'three', 4=>'four', 5=>'five', 6=>'six', 7=>'seven', 8=>'eight', 9=>'nine', 10=>'ten');
// Choose the first number randomly between 6 and 10. This is to stop the answer being negative.
$captcha_number_first = mt_rand(6, 10);
// Choose the second number randomly between 0 and 5.
$captcha_number_second = mt_rand(0, 5);
// Set up an array with the operators that we want to use. At this stage it is only subtraction and addition.
$captcha_operator_convert = array(0=>'+', 1=>'-', 2=>'*');
// Choose the operator randomly from the array.
$captcha_operator = $captcha_operator_convert[mt_rand(0, 2)];
// Get the equation in textual form to show to the user.
$captcha_return = (mt_rand(0, 1) == 1 ? $captcha_number_convert[$captcha_number_first] : $captcha_number_first) . ' ' . $captcha_operator . ' ' . (mt_rand(0, 1) == 1 ? $captcha_number_convert[$captcha_number_second] : $captcha_number_second);
// Evaluate the equation and get the result.
eval('$captcha_result = ' . $captcha_number_first . ' ' . $captcha_operator . ' ' . $captcha_number_second . ';');
// Store the result in a session key.
$_SESSION['main_captcha'] = $captcha_result;
// Return the question along with a bit of text in front as it will be used in the form itself.
return 'What is the answer to ' . $captcha_return . '?';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>An Example Of The PHP Math Captcha</title>
</head>
<body>
<script type="text/javascript" src="includes/verifyAddress.js"></script>
<script type="text/javascript">
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</script>

<form action="" method="post">
<table>
<tr>
<td>
<label for=""><?php echo(main_captcha()); ?></label>
</td>
<td>
<input id="example_captcha" type="text" name="example_captcha" />
</td>
</tr>
<tr>
<td colspan="2" align="">
<input type="submit" name="example_submit" value="Test The Captcha!" />
</td>
</tr>
</table>
</form>
</body>
</html>

 

I don't know what I am missing here...

 

 

 

Edit:

 

Never mind.  I just saw it.  On the page that works, the CAPTCHA script is loaded before the HTML and on the page that doesn't, it is imbeded in the HTML

Link to comment
Share on other sites

Ok... hopefully, the last question.

 

When the CAPTCHA is answered incorrectly, the page reloads.  However, when the page first loads, it displays options that the customer picked on the prior screen (the CAPTCHA page is a middleman between the main form and the entry.php page).

 

The information that is displayed comes in on a loop, like:

if(isset($POST['54']));
{
$professional = $_POST['54'];
$p	=	count($professional);
$pi	=	0;

if ($p == 0){
}
else {
echo "<ul><li>Professional, scientific, and technical services (54) Reports:</li> \r\n";
echo "<ul>";
while ($pi<$p)
{
	echo "<li><b>{$professional[$pi]}</b></li>\r\n";
	$pi++;
	}
	echo "</ul>";
}
echo "</ul>";
}

 

I don't want to lose this information on a reload.  I figure I have to use $_SESSION variables?  (Or is there another way?)

 

How can I declare the $_SESSION variables within the loop and then have them displayed correctly?

 

Thanks!!

Link to comment
Share on other sites

Just in case I am not clear enough..

 

Page 1 has a form where a customer has the opportunity to select from a series of options (a series of tables with checkboxes).  Upon Submit, all the info is sent to Page2.  Page 2 displays the options they chose (looping) and has them solve the CAPTCHA.  If they get the CAPTCHA wrong, I want to refresh the page while keeping their looped answers.  If correct, Page 2 will submit the info and send the customer to Page 3 which tells them (among other things) their order has been processes.

 

Is that more clear?

Link to comment
Share on other sites

By the way, here is the page that is supposed to process the customer's info upon a successful CAPTCHA (or to ask again if the CAPTCHA is answered incorrectly)

 

<?php
// Start up your PHP session. The captcha does not work without this enabled.
session_start();
// Check if the form has been submitted.
if(isset($_POST['example_submit']))
{
// The form has been submitted, so let's check if the captcha has been entered correctly.
if($_POST['example_captcha'] == $_SESSION['main_captcha'])
{
	// It worked! If you want to process other types of form information, this is where you will do it.
	// I just simply print the value of the name text box out onto the screen here.

	$name=$_POST['email'];
	$today = date("mdY");			
                          $file = $today.'notifyme.txt';
	$handle21 = fopen($file, 'a');
	foreach($_POST['21'] as $naicscode21){
	      $content21 .= $name . '^'.$naicscode21."\n";
				}
	fwrite($handle21, $content21);

	$name=$_POST['email'];
	$handle22 = fopen($file, 'a');
	foreach($_POST['22'] as $naicscode22){
	      $content22 .= $name . '^'.$naicscode22."\n";
	}
	fwrite($handle22, $content22);

	$email = $_SESSION['email'];
	$name=$_POST['email'];
	$handle23 = fopen($file, 'a');
	foreach($_POST['23'] as $naicscode23){
	     $content23 .= $name . '^'.$naicscode23."\n";
	}
	fwrite($handle23, $content23);

	$name=$_POST['email'];
	$handle31 = fopen($file, 'a');
	foreach($_POST['31'] as $naicscode31){
	     $content31 .= $name . '^'.$naicscode31."\n";
	}
	fwrite($handle31, $content31);

		$name=$_POST['email'];
	$handle42 = fopen($file, 'a');
	foreach($_POST['42'] as $naicscode42){
   	 $content42 .= $name . '^'.$naicscode42."\n";
	}
	fwrite($handle42, $content42);

	$name=$_POST['email'];
	$handle44 = fopen($file, 'a');
	foreach($_POST['44'] as $naicscode44){
	     $content44 .= $name . '^'.$naicscode44."\n";
	}
	fwrite($handle44, $content44);

	$name=$_POST['email'];
	$handle48 = fopen($file, 'a');
	foreach($_POST['48'] as $naicscode48){
	     $content48 .= $name . '^'.$naicscode48."\n";
	}
	fwrite($handle48, $content48);

	$name=$_POST['email'];
	$handle51 = fopen($file, 'a');
	foreach($_POST['51'] as $naicscode51){
	     $content51 .= $name . '^'.$naicscode51."\n";
	}
	fwrite($handle51, $content51);

	$name=$_POST['email'];
	$handle52 = fopen($file, 'a');
	foreach($_POST['52'] as $naicscode52){
              $content52 .= $name . '^'.$naicscode52."\n";
	}
	fwrite($handle52, $content52);

	$name=$_POST['email'];
	$handle53 = fopen($file, 'a');
	foreach($_POST['53'] as $naicscode53){
	     $content53 .= $name . '^'.$naicscode53."\n";
	}
	fwrite($handle53, $content53);

	$name=$_POST['email'];
	$handle54 = fopen($file, 'a');
	foreach($_POST['54'] as $naicscode54){
                	      $content54 .= $name . '^'.$naicscode54."\n";
	}
	fwrite($handle54, $content54);

	$name=$_POST['email'];
	$handle55 = fopen($file, 'a');
	foreach($_POST['55'] as $naicscode55){
               $content55 .= $name . '^'.$naicscode55."\n";
	}
	fwrite($handle55, $content55);

	$name=$_POST['email'];
	$handle56 = fopen($file, 'a');
	foreach($_POST['56'] as $naicscode56){
	     $content56 .= $name . '^'.$naicscode56."\n";
	}
	fwrite($handle56, $content56);

	$name=$_POST['email'];
	$handle61 = fopen($file, 'a');
	foreach($_POST['61'] as $naicscode61){
	  $content61 .= $name . '^'.$naicscode61."\n";
	}
	fwrite($handle61, $content61);

	$name=$_POST['email'];
	$handle62 = fopen($file, 'a');
	foreach($_POST['62'] as $naicscode62){
	     $content62 .= $name . '^'.$naicscode62."\n";
	}
	fwrite($handle62, $content62);

	$name=$_POST['email'];
	$handle71 = fopen($file, 'a');
	foreach($_POST['71'] as $naicscode71){
	     $content71 .= $name . '^'.$naicscode71."\n";
	}
	fwrite($handle71, $content71);

	$name=$_POST['email'];
	$handle72 = fopen($file, 'a');
	foreach($_POST['72'] as $naicscode72){
	     $content72 .= $name . '^'.$naicscode72."\n";
	}
	fwrite($handle72, $content72);
		$name=$_POST['email'];
	$handle81 = fopen($file, 'a');
	foreach($_POST['81'] as $naicscode81){
	     $content81 .= $name . '^'.$naicscode81."\n";
	}
	fwrite($handle81, $content81);

	echo "Thank you!  Your notification request has been submitted.";


}
else
{
	// Oh no, they got it wrong, so we'll tell them to try it again.
	echo ('You answered the bot check incorrectly.'); 
}
}

// Here, we've included the actual captcha function. You can change the name to whatever you'd like.
function main_captcha()
{
// First of all we are going to set up an array with the text equivalents of all the numbers we will be using.
$captcha_number_convert = array(0=>'zero', 1=>'one', 2=>'two', 3=>'three', 4=>'four', 5=>'five', 6=>'six', 7=>'seven', 8=>'eight', 9=>'nine', 10=>'ten');
// Choose the first number randomly between 6 and 10. This is to stop the answer being negative.
$captcha_number_first = mt_rand(6, 10);
// Choose the second number randomly between 0 and 5.
$captcha_number_second = mt_rand(0, 5);
// Set up an array with the operators that we want to use. At this stage it is only subtraction and addition.
$captcha_operator_convert = array(0=>'+', 1=>'-');
// Choose the operator randomly from the array.
$captcha_operator = $captcha_operator_convert[mt_rand(0, 1)];
// Get the equation in textual form to show to the user.
$captcha_return = (mt_rand(0, 1) == 1 ? $captcha_number_convert[$captcha_number_first] : $captcha_number_first) . ' ' . $captcha_operator . ' ' . (mt_rand(0, 1) == 1 ? $captcha_number_convert[$captcha_number_second] : $captcha_number_second);
// Evaluate the equation and get the result.
eval('$captcha_result = ' . $captcha_number_first . ' ' . $captcha_operator . ' ' . $captcha_number_second . ';');
// Store the result in a session key.
$_SESSION['main_captcha'] = $captcha_result;
// Return the question along with a bit of text in front as it will be used in the form itself.
return 'What is the answer to ' . $captcha_return . '?';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

</head>
<body>

	  <h2>NotifyMe</h2>
	    <h3>You are almost done...</h3>
            <p>Please verify the information below. If any of it is incorrect 
              or incomplete, please go back to the previous page and make your 
              corrections.</p>


<?php
echo "You have requested that the following report notifications be sent to:<br /><br /> ";
echo "<blockquote><b>".$_POST['email'],"</b></blockquote>";

if(isset($POST['21']));
{
$mining = $_POST['21'];
$m	=	count($mining);
$mi	=	0;

if ($m == 0){
}
else {
echo "<ul><li>Mining, quarrying, and oil and gas extraction (21) reports:</li> \r\n";
echo "<ul>";
while ($mi<$m)
{
	echo "<li><b>{$mining[$mi]}</b></li>\r\n";
	$mi++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['22']));
{
$utilities = $_POST['22'];
$u	=	count($utilities);
$ui	=	0;

if ($u == 0){
}
else {
echo "<ul><li>Utilities (22) reports:</li> \r\n";
echo "<ul>";
while ($ui<$u)
{
	echo "<li><b>{$utilities[$ui]}</b></li>\r\n";
	$ui++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['23']));
{
$construction = $_POST['23'];
$c	=	count($construction);
$ci	=	0;

if ($c == 0){
}
else {
echo "<ul><li>Construction (23) reports:</li> \r\n";
echo "<ul>";
while ($ci<$c)
{
	echo "<li><b>{$construction[$ci]}</b></li>\r\n";
	$ci++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['31']));
{
$manufacturing = $_POST['31'];
$ma	=	count($manufacturing);
$mai	=	0;

if ($ma == 0){
}
else {
echo "<ul><li>Manufacturing (31 - 33) reports:</li> \r\n";
echo "<ul>";
while ($mai<$ma)
{
	echo "<li><b>{$manufacturing[$mai]}</b></li>\r\n";
	$mai++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['42']));
{
$wholesale = $_POST['42'];
$w	=	count($wholesale);
$wi	=	0;

if ($w == 0){
}
else {
echo "<ul><li>Wholesale trade (42) reports:</li> \r\n";
echo "<ul>";
while ($wi<$w)
{
	echo "<li><b>{$wholesale[$wi]}</b></li>\r\n";
	$wi++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['44']));
{
$retail = $_POST['44'];
$r	=	count($retail);
$ri	=	0;

if ($r == 0){
}
else {
echo "<ul><li>Retail trade (44 - 45) reports:</li> \r\n";
echo "<ul>";
while ($ri<$r)
{
	echo "<li><b>{$retail[$ri]}</b></li>\r\n";
	$ri++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['48']));
{
$transportation = $_POST['48'];
$t	=	count($transportation);
$ti	=	0;

if ($t == 0){
}
else {
echo "<ul><li>Transportation and warehousing (48 - 49) reports:</li> \r\n";
echo "<ul>";
while ($ti<$t)
{
	echo "<li><b>{$transportation[$ti]}</b></li>\r\n";
	$ti++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['51']));
{
$information = $_POST['51'];
$inf	=	count($information);
$infi	=	0;

if ($inf == 0){
}
else {
echo "<ul><li>Information (51) reports:</li> \r\n";
echo "<ul>";
while ($infi<$inf)
{
	echo "<li><b>{$information[$infi]}</b></li>\r\n";
	$infi++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['52']));
{
$finance = $_POST['52'];
$f	=	count($finance);
$fi	=	0;

if ($f == 0){
}
else {
echo "<ul><li>Finance Reports (52):</li> \r\n";
echo "<ul>";
while ($fi<$f)
{
	echo "<li><b>{$finance[$fi]}</b></li>\r\n";
	$fi++;
	}
	echo "</ul>";
}
echo "</ul>";
}

/* start */
if(isset($POST['54']));
{
$professional = $_POST['54'];
$p	=	count($professional);
$pi	=	0;

if ($p == 0){
}
else {
echo "<ul><li>Professional, scientific, and technical services (54) Reports (52):</li> \r\n";
echo "<ul>";
while ($pi<$p)
{
	echo "<li><b>{$professional[$pi]}</b></li>\r\n";
	$pi++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['55']));
{
$management = $_POST['55'];
$mg	=	count($management);
$mgi	=	0;

if ($mg == 0){
}
else {
echo "<ul><li>Management of companies and enterprises (55) Reports:</li> \r\n";
echo "<ul>";
while ($mgi<$mg)
{
	echo "<li><b>{$management[$mgi]}</b></li>\r\n";
	$mgi++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['56']));
{
$administration = $_POST['56'];
$a	=	count($administration);
$ai	=	0;

if ($a == 0){
}
else {
echo "<ul><li>Administrative and support and waste management and remediation services (56) Reports:</li> \r\n";
echo "<ul>";
while ($ai<$a)
{
	echo "<li><b>{$administration[$ai]}</b></li>\r\n";
	$ai++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['61']));
{
$education = $_POST['61'];
$e	=	count($education);
$ei	=	0;

if ($e == 0){
}
else {
echo "<ul><li>Educational services (61) Reports:</li> \r\n";
echo "<ul>";
while ($ei<$e)
{
	echo "<li><b>{$education[$ei]}</b></li>\r\n";
	$ei++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['62']));
{
$healthcare = $_POST['62'];
$h	=	count($healthcare);
$hi	=	0;

if ($h == 0){
}
else {
echo "<ul><li>Health care and social services (62) Reports:</li> \r\n";
echo "<ul>";
while ($hi<$h)
{
	echo "<li><b>{$healthcare[$hi]}</b></li>\r\n";
	$hi++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['71']));
{
$arts = $_POST['71'];
$ar	=	count($arts);
$ari	=	0;

if ($ar == 0){
}
else {
echo "<ul><li>Arts, entertainment, and recreation (71) Reports:</li> \r\n";
echo "<ul>";
while ($ari<$ar)
{
	echo "<li><b>{$arts[$ari]}</b></li>\r\n";
	$ari++;
	}
	echo "</ul>";
}
echo "</ul>";
}

if(isset($POST['81']));
{
$other = $_POST['81'];
$o	=	count($other);
$oi	=	0;

if ($o == 0){
}
else {
echo "<ul><li>Other services (except public administration) (81) Reports:</li> \r\n";
echo "<ul>";
while ($oi<$o)
{
	echo "<li><b>{$other[$oi]}</b></li>\r\n";
	$oi++;
	}
	echo "</ul>";
}
echo "</ul>";
}
?>
<p>If your information is correct, please answer the following mathematical question.  
This will prove to us that you are a real person and not some evil bot. Entering the 
correct answer and clicking Submit will complete your registration.  Thank you for 
using the NotifyMe system from the U.S. Census Bureau for the 2007 Economic Census.</p>


<form action="" method="post">
<table>
<tr>
<td>
<label for=""><?php echo(main_captcha()); ?></label>
</td>
<td>
<input id="example_captcha" type="text" name="example_captcha" />
</td>
</tr>
<tr>
<td colspan="2" align="">
<input type="submit"  name="example_submit" value="Test The Captcha!" />
</td>
</tr>
</table>
</form>


</body>
</html>

Link to comment
Share on other sites

you can create session variables in a loop, but it would be easier if you had cleaner code.

Regardless, here is a possible working solution.

session_start();
$fields = array('example_submit', "email", "21", "22", "23");//This needs to be a complete list of the fields you want to save from the form. You'll need to complete this list because I do not care to do so for you ;-)
foreach($fields as $post){
if(isset($_POST[$post])){
	$_SESSION[$post] = $_POST[$post];
} else if(isset($_SESSION[$post])) {
	$_POST[$post] = $_SESSION[$post];
}
}

See where it says session_start() in your code, over lap it so that you don't have two "session_start()" which will cause a warning.

 

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.