phpspidercookie

<?php
/**
 * Created by PhpStorm.
 * User: brady
 * Date: 2016/12/9
 * Time: 17:32
 */
ini_set("memory_limit", "1024M");
require dirname(__FILE__).‘/../core/init.php‘;

// 登录请求url
$login_url = "http://www.waduanzi.com/login?url=http%3A%2F%2Fwww.waduanzi.com%2Fmember";
// 提交的参数
$params = array(
    "LoginForm[returnUrl]" => "http%3A%2F%2Fwww.waduanzi.com%2Fmember"
,
    "LoginForm[username]" => "13544194267",
    "LoginForm[password]" => "aa5421010",
    "LoginForm[rememberMe]" => 0,
    "LoginForm[rememberMe]" => 1,
    "yt0" => "登录",
);
// 发送登录请求
requests::post($login_url, $params);
// 登录成功后本框架会把Cookie保存到www.waduanzi.com域名下,我们可以看看
$cookies = requests::get_cookies("www.waduanzi.com");
// requests对象自动收集Cookie,访问这个域名下的URL会自动带上
// 接下来我们来访问一个需要登录后才能看到的页面
$url = "http://www.waduanzi.com/member";
$cookies = implode(";", $cookies);
// 把Cookie设置到 weibo.com 域名下
requests::set_cookies($cookies, "http://www.waduanzi.com");
$html = requests::get($url);
echo $html; // 可以看到登录后的页面,非常棒

  

<?php/** * Created by PhpStorm. * User: brady * Date: 2016/12/9 * Time: 17:32 */ini_set("memory_limit", "1024M");require dirname(__FILE__).‘/../core/init.php‘;

// 登录请求url$login_url = "http://www.waduanzi.com/login?url=http%3A%2F%2Fwww.waduanzi.com%2Fmember";// 提交的参数$params = array("LoginForm[returnUrl]" => "http%3A%2F%2Fwww.waduanzi.com%2Fmember","LoginForm[username]" => "13544194267","LoginForm[password]" => "aa5421010","LoginForm[rememberMe]" => 0,"LoginForm[rememberMe]" => 1,"yt0" => "登录",);// 发送登录请求requests::post($login_url, $params);// 登录成功后本框架会把Cookie保存到www.waduanzi.com域名下,我们可以看看$cookies = requests::get_cookies("www.waduanzi.com");// requests对象自动收集Cookie,访问这个域名下的URL会自动带上// 接下来我们来访问一个需要登录后才能看到的页面$url = "http://www.waduanzi.com/member";$cookies = implode(";", $cookies);// 把Cookie设置到 weibo.com 域名下requests::set_cookies($cookies, "http://www.waduanzi.com");$html = requests::get($url);echo $html; // 可以看到登录后的页面,非常棒
时间: 2024-10-10 02:56:10

phpspidercookie的相关文章