下面是本站的代码,希望对大家有帮助。
<?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[朗读]
加入收藏