我有这个完美运行的代码。但是,在我提交之后,我被重定向到外部网站,在那里可以看到结果。相反,我希望结果显示在同一个网站上。我愿意接受各种建议!
问问题
1701 次
1 回答
2
第一行应该是:
echo '<form action="' . $_SERVER[PHP_SELF] . '" method="post">
然后在您回显的最后一行上方,输入:
$response = curl_exec($ch);
另外,将您的位置线更改为:
$location = 'http://results.vtu.ac.in/vitavi.php';
- - -编辑 - - -
我添加了一些代码来为您解析响应,最终代码将是:
<?php
echo '<form action="' . $_SERVER[PHP_SELF] . '" method="post">
<input type="text" name="rid">
<input type="submit" name="submit" value="submit">
</form>';
if(isset($_POST['submit'])&&(!empty($_POST['rid'])))
{
$location = 'http://results.vtu.ac.in/vitavi.php';
$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $location );
$post_array = array(
"rid" => $_POST['rid'],
"submit" => "submit"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
$response = curl_exec($ch);
$start = '<TD width="513">';
$end = '<br>';
$response = strstr($response, $start);
$end = stripos($response, $end);
$response = substr($response, strlen($start), $end - strlen($start));
echo $response."<br/>";
}
?>
于 2012-12-16T08:19:45.040 回答