dtds8802 2014-07-12 14:32
浏览 22

curl没有从外部网站收集所有cookie

for some reason , its not collecting all the cookies, its not collecting the password hash or the member id , im not sure why its not setting those since its getting the others, am i doing somthing wrong with my coding, this is my first time using curl

this is the information in the cookie.txt file

<?php
//init curl

function curl_file_get_contents($url){
    $username = 'user@hotmail.com';
    $password = 'mypass';
    $loginUrl = 'http://forums.zybez.net/index.php?app=curseauth&module=global&section=login';

    //init curl
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($ch, CURLOPT_URL, $loginUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'user=' . $username . '&pass=' . $password);
    $store = curl_exec($ch);
    curl_setopt($ch, CURLOPT_REFERER, 'http://forums.zybez.net/runescape-2007-prices/282-law+rune');

    $content = curl_exec($ch);

    curl_close($ch);

    file_put_contents('~/download.zip', $content);

    $curl = curl_init();

    curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($curl, CURLOPT_VERBOSE, true);
    curl_setopt($curl, CURLOPT_REFERER, $loginUrl);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
    $contents = curl_exec($curl);

    return $contents;
    curl_close($curl);
}

function get_input_tags($html){
    $post_data = array();

    // a new dom object
    $dom = new DomDocument;

    //load the html into the object
    $dom->loadHTML($html);
    //discard white space
    $dom->preserveWhiteSpace = false;

    //all input tags as a list
    $input_tags = $dom->getElementsByTagName('input');

    //get all rows from the table
    for ($i = 0; $i < $input_tags->length; $i++) {
        if (is_object($input_tags->item($i))) {
            $name   = $value = '';
            $name_o = $input_tags->item($i)->attributes->getNamedItem('name');
            if (is_object($name_o)) {
                $name = $name_o->value;

                $value_o = $input_tags->item($i)->attributes->getNamedItem('value');
                if (is_object($value_o)) {
                    $value = $input_tags->item($i)->attributes->getNamedItem('value')->value;
                }

                $post_data[$name] = $value;
            }
        }
    }
    return $post_data;
}

/*
Usage
*/

error_reporting(~E_WARNING);

function getauth(){
    $html = curl_file_get_contents("http://forums.zybez.net/runescape-2007-prices/282-law+rune");

    echo "<pre>";
    $auth1 = (get_input_tags($html));
    $auth  = $auth1["auth"];

    print_r($auth1);

}
getauth();
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用