首页 > curl_setopt

php获取http状态码程序代码

经常需要判断文件是否可以访问,可以通过http状态码判别,200为正常访问,404为找不到该页面,代码如下

<?php
// 设置url
http://pic2.phprm.com/2013/07/27/$url.jpg = 'http://www.phprm.com';
function get_http_status_code($url) {
 if(empty($url)) return false;
 $url = parse_url($url);
 $host = isset($url['host']) ? $url['host'] : '';
 $port = isset($url['port']) ? $url['port'] : '80';
 $path = isset($url['path']) ? $url['path'] : '';
 $query = isset($url['query']) ? $url['query'] : '';

阅读全文

php curl采集远程页面内容演示代码

$curlPost = 'a=1&b=2';//模拟POST数据
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:0.0.0.0', 'CLIENT-IP:0.0.0.0'));  //构造IP
curl_setopt($ch, CURLOPT_REFERER, "http://www.phprm.com");   //构造来路
curl_setopt($ch,CURLOPT_URL, 'http://www.phprm.com');//需要抓取的页面路径
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);//post值

阅读全文

php curl 伪造IP来源程序实现代码

定义伪造用户浏览器信息HTTP_USER_AGENT

$binfo =array('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar)','Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0','Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)','Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1)',$_SERVER['HTTP_USER_AGENT']);
//123.125.68.*
//125.90.88.*

阅读全文

PHP 获取远程文件大小常用方法总结

1、fsockopen

<?php
function getFileSize(http://pic1.phprm.com/2013/07/11/$url.jpg){
$url = parse_url($url);
if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){
fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1rn");
fputs($fp,"Host:$url[host]rnrn");
while(!feof($fp)){
$tmp = fgets($fp);
if(trim($tmp) == ''){
break;
}else if(preg_match('/Content-Length:(.*)/si',$tmp,$arr)){
return trim($arr[1]);
}
}
return null;
}else{
return null;
}
}
//调用方法
echo getFileSize("http://www.phprm.comnet/")
?>

阅读全文

PHP 利用curl_init发起http请求模仿登录

备注:使用curl_init函数,必须要打开这个php扩展。

1.打开php.ini,开启extension=php_curl.dll
2.检查php.ini的extension_dir值是哪个目录,检查有无php_curl.dll,没有的请下载php_curl.dll,再把php目录中的libeay32.dll,ssleay32.dll拷到c:/windows/system32里面。

阅读全文

PHP CURL用法详解

PHP中的CURL函数库(Client URL Library Function)

curl_close — 关闭一个curl会话
curl_copy_handle — 拷贝一个curl连接资源的所有内容和参数
curl_errno — 返回一个包含当前会话错误信息的数字编号
curl_error — 返回一个包含当前会话错误信息的字符串
curl_exec — 执行一个curl会话
curl_getinfo — 获取一个curl连接资源句柄的信息
curl_init — 初始化一个curl会话
curl_multi_add_handle — 向curl批处理会话中添加单独的curl句柄资源
curl_multi_close — 关闭一个批处理句柄资源
curl_multi_exec — 解析一个curl批处理句柄
curl_multi_getcontent — 返回获取的输出的文本流
curl_multi_info_read — 获取当前解析的curl的相关传输信息
curl_multi_init — 初始化一个curl批处理句柄资源
curl_multi_remove_handle — 移除curl批处理句柄资源中的某个句柄资源
curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array — 以数组的形式为一个curl设置会话参数
curl_setopt — 为一个curl设置会话参数
curl_version — 获取curl相关的版本信息

阅读全文