下面是本站的代碼,希望對大家有幫助。
<?php
//參數1:訪問的url,參數2:post數據(不填則為get),參數3:提交的$cookies,參數4:是否返回$cookies
function curl_request($url,$post='',$json=true,$pjson=false,$lower=true,$cookie='',$returncookie=0){
$curl = curl_init();
curl_setopt($curl,curlopt_url,$url);
curl_setopt($curl,curlopt_followlocation,1);
curl_setopt($curl,curlopt_autoreferer,1);
curl_setopt($curl,curlopt_httpheader,["content-type"=>"application/json;charset=utf-8"]);
if($post) {
curl_setopt($curl,curlopt_post,1);
curl_setopt($curl,curlopt_postfields,$pjson?json_encode($post,320):http_build_query($post));
}
if($cookie) {
curl_setopt($curl,curlopt_cookie,$cookie);
}
curl_setopt($curl,curlopt_header,$returncookie);
curl_setopt($curl,curlopt_timeout,10);
curl_setopt($curl,curlopt_returntransfer,1);
$data = curl_exec($curl);
if (curl_errno($curl)) {
//return curl_error($curl);
return false;
}
echo curl_getinfo($curl,curlinfo_http_code);
curl_close($curl);
if($returncookie){
list($header,$body) = explode("\r\n\r\n",$data,2);
preg_match_all("/set\-cookie:([^;]*);/",$header,$matches);
$info['cookie'] = substr($matches[1][0],1);
$info['content'] = $body;
return $info;
}else{
if($lower) $data=strtolower($data);
if($json) return json_decode($data);else return $data;
}
}
$dbms='mysql'; //資料庫類型。
$host='localhost';//資料庫主機名。
$dbname='xxxx'; //使用的資料庫。
$dsn="$dbms:host=$host;dbname=$dbname";
try {
$dbh = new pdo($dsn,'xxx','xxxx');//初始化一個pdo對象。
$query=$dbh->query('select `url` from `nip_indexnow` limit 0,10');
if($urllist=$query->fetchall(pdo::fetch_column) and count($urllist)>0){
var_dump(curl_request('https://yandex.com/indexnow',['host'=>'www.lcget.com','key'=>'xxxxxxx','keylocation'=>'https://www.lcget.com/xxxx.txt','urllist'=>$urllist],true,true));
var_dump( curl_request('https://www.bing.com/indexnow',['host'=>'www.lcget.com','key'=>'xxxx','keylocation'=>'https://www.lcget.com/xxx.txt','urllist'=>$urllist],true));
$dbh->exec('delete from `nip_indexnow` limit 10');
}
} catch (pdoexception $e) {
die ("error!:".$e->getmessage()."<br/>");
}
- 編程問答
- 答案列表
php提交indexnow[朗讀]
加入收藏