我有两页:
一个.php
<?php if($_POST && $_POST['captcha'] == 'thisisrandom'){
echo 'KEY = ' . uniqid();
} ?>
<form action="one.php" method="POST">
NAME: <input type="text" name="name"> <br />
CAPTCHA: <input type="text" name="captcha"> <br />
<input type="submit">
</form>
二.php
<?php
function get_web_page($url)
{
//echo "curl:url<pre>".$url."</pre><BR>";
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 15, // timeout on connect
CURLOPT_TIMEOUT => 15, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init($url);
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch,CURLINFO_EFFECTIVE_URL );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
//change errmsg here to errno
if ($errmsg)
{
echo "CURL:".$errmsg."<BR>";
}
return $content;
}
print_r(get_web_page('http://localhost/one.php'));
?>
我打开页面two.php。这向我展示了one.php的表单。这没关系,但如果我提交表单,那么这会将我重定向到one.php。如何在 two.php 页面上填写此表单、提交表单并在 one.php 页面上从 one.php 接收数据而无需重定向?