CURL模拟登陆

index.html
<a href="http://adtuu-server.com/login/login.php?auth_username=admin&auth_password=admin123">Login</a>

admincp.php
<?php
$username = $_POST['auth_username'];
$password = $_POST['auth_password'];

if ($username == 'admin' && $password == 'admin123') {
    echo 'ok';
} else {
    echo 'error.';
}

login.php
<?php
if (isset($_GET['auth_username']) && isset($_GET['auth_password'])) {

    $user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)"; 

    $header = array (   
        "Host:www.adtuu-server.com",    
        "Referer: http://www.adtuu-server.com/login/login.php",   
    ); 

    $data = array(
        'auth_username' => $_GET['auth_username'],
        'auth_password' => $_GET['auth_password']
    );

    $url = 'http://www.adtuu-server.com/login/admincp.php';

    $curl = curl_init (); // 启动一个CURL会话 
    curl_setopt ( $curl, CURLOPT_URL, $url ); // 要访问的地址 
    curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, 0 ); // 对认证证书来源的检查 
    // curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, 1 ); // 从证书中检查SSL加密算法是否存在 
    curl_setopt ( $curl, CURLOPT_USERAGENT, $user_agent ); // 模拟用户使用的浏览器 
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);  //设置头信息的地方   
    @curl_setopt ( $curl, CURLOPT_FOLLOWLOCATION, 1 ); // 使用自动跳转     
    // curl_setopt ( $curl, CURLOPT_HTTPGET, 1 ); // 发送一个常规的GET请求 
    curl_setopt ( $curl, CURLOPT_POST, 1 ); // 发送一个常规的Post请求 
    curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data ); // Post提交的数据包 

    // curl_setopt ( $curl, CURLOPT_COOKIE, $cookie); // 直接发送cookie内容 
    // curl_setopt($curl,CURLOPT_COOKIEFILE, $cookieFile); //发送Cookie文件 
    curl_setopt ( $curl, CURLOPT_TIMEOUT, 120 ); // 设置超时限制防止死循环 
    curl_setopt ( $curl, CURLOPT_HEADER, 0 ); // 不显示返回的Header区域内容 
    curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 ); // 获取的信息以文件流的形式返回 

    $res = curl_exec ( $curl ); // 执行操作 

    if (curl_errno ( $curl )) { 
        die('失败:Errno' . curl_error ( $curl )); 
    } 

    curl_close ( $curl ); // 关闭CURL会话 

    // header('Location:http://www.adtuu-server.com/login/admincp.php');
    echo $res;
    exit;
}
?>

<form action="http://www.adtuu-server.com/login/admincp.php" method="post">
<input type="text" name="auth_username" /><br />
<input type="password" name="auth_password" value="" /><br />
<input type="submit" value="Login" /><br />
</form>

  

posted @ 2015-07-30 09:42  Adtuu  阅读(163)  评论(0编辑  收藏  举报