curl 设置session
想通过curl为另一个域名设置一个session,但试了好长时间总是不行?
www.abc.com/curl.php
www.123.com/setsession.php
www.abc.com/curl.php
$postdata = "user=admin";
$post = array(
"post" =>$postdata
);
curl_http_open("http://www.123.com/setsession.php",$post);
function curl_http_open($url, $conf = array())
{
if (!function_exists('curl_init') or !is_array($conf)){
return false;
}
$post = '';
$purl = parse_url($url);
$arr = array('post' => true, 'return' => true, 'cookie' => '', );
$arr = array_merge($arr, $conf);
$ch = curl_init();
if ($purl['scheme'] == 'https') {
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $arr['return']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $arr['cookie']);
curl_setopt($ch, CURLOPT_COOKIEFILE, $arr['cookie']);
if ($arr['post'] != false) {
curl_setopt($ch, CURL_POST, true);
if (is_array($arr['post'])) {
$post = http_build_query($arr['post']);
} else {
$post = $arr['post'];
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
www.123.com/setsession.php
session_start();
$user = $_REQUEST['user'];
//此处能取到$user值
if(!empty($user)){
$_SESSION['cuser'] = $user;
}
//
print_r($_SESSION['cuser']);
...全文
相关推荐
PHP使用curl制作简易百度搜索
主要为大家详细介绍了PHP使用curl制作简易百度搜索的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
PHP curl模拟浏览器采集阿里巴巴的实现代码
都说阿里巴巴有不能采集和防采集的神话,今天就用张老师讲的Curl采集写了一个模拟浏览器的代码。
php curl抓取网页的介绍和推广及使用CURL抓取淘宝页面集成方法
抓取网页内容,分析网页数据经常使用php curl,简洁易用,本篇文章通过代码实例给大家讲解 php curl抓取网页的介绍和推广及使用CURL抓取淘宝页面集成方法,需要的朋友参考下
PHP使用CURL实现下载文件功能示例
主要介绍了PHP使用CURL实现下载文件功能,结合具体实例形式分析了php基于curl的文件下载实现技巧,代码注释有详细的功能说明,并附带了curl参数的功能讲解,需要的朋友可以参考下
php下curl用法详解
curl看起来挺难的,这个文档比较全,可以作为api使用,帮助英文不好的同学们。


基础编程
