尝试使用curl_setopt从网站网址中检索结果

时间:2019-07-06 14:45:58

标签: php

我无法获得预期的结果,我一直加载索引页,而不是pPOST值以检索预期的数据

我尝试更改$url='http://eworld.nabtebnigeria.org/results.asp' 实际页面上的表单操作为action='results.asp'

<?php
function get_nabteb($examtype, $year,  $serial, $pin, $examno){
$url="http://eworld.nabtebnigeria.org/";    
$fields=array(
'candid' => urlencode(trim($examno)),
'examtype' => urlencode($examtype),
'examyear' => urlencode($year),
'serial' => urlencode($serial),
'pin' => urlencode($pin),
'emailcheck' => urlencode('1'),
'email' => urlencode(''),
'testcookie' => '1',
);

//print_r($fields);


    $ch = curl_init();

 $header[0] = "Accept: text/html, text/xml,application/xml,application/xhtml+xml,";
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: no-cache";
    $header[] ="Content-Type: application/x-www-form-urlencoded";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
  curl_setopt($ch,CURLOPT_COOKIEJAR, '/tmp/cookie.txt');
curl_setopt($ch,CURLOPT_COOKIEFILE,'/tmp/cookie.txt');

    echo $page = curl_exec($ch);

    echo $head = curl_getinfo($ch, CURLINFO_HEADER_OUT);
    echo curl_errno($ch) . '-' . curl_error($ch);
    //debug($head);
    //debug($page);

    curl_close($ch);
    return $page;
}
echo get_nabteb('01', '2013', 'NBRC14000856', '157328532669', 23062062);
?>

0 个答案:

没有答案