2012-12-16 60 views
2

我有完美的代碼。但是,在我提交之後,我被重定向到了可以看到結果的外部網站。相反,我希望結果顯示在同一個網站上。我願意接受各種建議!從同一頁上的外部網站獲取表單結果

+0

你可以使用jQuery嗎? –

+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/>"; 
} 

?> 
+0

不好,似乎沒有工作我已經上傳到我的網站,你可以檢查我試過你的代碼替換,www.enggnetwork.com/awesome.php和你可以輸入的值是「1nc09cs065」,這是我的大學卷。數。 –

+0

進行了另一次編輯,您還需要更改$ location行。您可能不想僅輸出$響應,而是希望使用一些字符串方法從HTML中提取要查找的內容,但如果您需要幫助,則應該啓動另一個線程。 – Michael

+0

好的,當然,謝謝,我會試試這個! –