POST值不会出现在recaptcha中

I have this page which contains a form. The values are POSTed over to the next page(check_values.php) which manipulates these values. Now I want to add a captcha. but it requires you to redirect the form to a verify.php which seems to clear out the posted variables when i redirect to check_values.php. I dont want to use session variables in this case. Are there any other method(s) to accomplish this.

Yep, POST won't persist after a page request. You'll have to resend them somehow.

If you want to stick with POST, inside the validate page you could populate a form with the POSTed variables, and submit it using a Javascript. Something like

<form id='blah' method='post' action='check_values.php'>
    <input type='hidden' value='<?php echo $_POST['var1']; ?>' />
    <input type='hidden' value='<?php echo $_POST['var2']; ?>' />
</form>

<script type='text/javascript'>
    document.getElementById("blah").submit();
</script>

Another option is stream_context_create, where you can send a redirect header with POST data. But this may only be useful for opening a stream, and the redirect could be difficult.


Of course, the easy way is just use a redirect header and send the data using GET, as @asprin explains.

You can use query strings too

In your verify.php page, add a query string to the location i.e.,

header('Location: check_values.php?captcha='.$postedValue.'');

Then in check_values.php, you can use $_GET to capture that value.

$value = $_GET['captcha'];

But make sure you sanitize all data coming from the query string