我有这个完美的代码。但是,在我提交之后,我被重定向到外部网站,可以看到结果。相反,我希望结果显示在同一个网站上。我愿意接受各种建议!
答案 0 :(得分: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/>";
}
?>