CURL有关问题

Jun 13, 2016 am 10:52 AM
cookie curl quot

CURL问题
问什么下面这段代码得不到正确的cookie?

$url = "http://www.edai365.cn/Index/login.aspx";
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; TheWorld)";
$cookie = "cnzz_eid=43361819-1349499907-&ntime=1349499907&cnzz_a=1&retime=1349499930944&sin=none<ime=1349499930944&rtime=0";
$ch= curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_REFERER, "http://www.edai365.cn/Index/login.aspx");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);
curl_exec($ch);
$tempCn = curl_multi_getcontent($ch);
curl_close($ch);
echo $tempCn;


------解决方案--------------------
$cookie_jar="";
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
指定一个cookie的保存地址;
用的时候
加上curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);

不知道符不符合你的要求
------解决方案--------------------
不知道你想干什么
http://www.edai365.cn/Index/login.aspx 是登陆页面,核心是一个表单
如果你是想模拟登陆,至少也需要模拟提交的表单数据
------解决方案--------------------
我測試了一下,可以抓取到成功登录的信息,至于为何进入登陆页面我也没有研究明白.

PHP code
// 模拟请求数据Function request($url,$postfields,$referer='',$cookie_jar='./cookie.txt'){    $Cur = curl_init();    $Opt = Array(        CURLOPT_URL => $url,        CURLOPT_HEADER => 1,        CURLOPT_NOBODY => 1,        CURLOPT_PORT => 80,    //端口        CURLOPT_POST => 1,    //发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。        CURLOPT_POSTFIELDS => $postfields,//要传送的所有数据,如果要传送一个文件,[email protected]        CURLOPT_RETURNTRANSFER => 1,// 获取的信息以文件流的形式返回,而不是直接输出。        CURLOPT_SSL_VERIFYHOST => 1,// 从证书中检查SSL加密算法是否存在        CURLOPT_SSL_VERIFYPEER => 0,// 对认证证书来源的检查,0表示阻止对证书的合法性的检查。        CURLOPT_COOKIE => GetCook($url),        CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)",//模拟用户使用的浏览器,在HTTP请求中包含一个"user-agent"头的字符串。        //CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1',        CURLOPT_FOLLOWLOCATION => 0,        CURLOPT_COOKIEJAR => Dirname(__FILE__).$cookie_jar,        CURLOPT_COOKIEFILE => Dirname(__FILE__).$cookie_jar,        CURLOPT_REFERER => $referer,    );    curl_setopt_array($Cur,$Opt);    $code = curl_exec($Cur);    curl_close($Cur);    Unset($Cur);    Return $code;}Function GetCook($url) {    $Curl=curl_init($url);    curl_setopt($Curl,CURLOPT_HEADER,1);    curl_setopt($Curl,CURLOPT_RETURNTRANSFER,1);    $Cook=curl_exec($Curl);    curl_close($Curl);    $Out='';    preg_match("/_SessionId\=(.[^;]*)/i",$Cook,$Out);    Return $Out[1];}$url = "http://www.edai365.cn/Index/login.aspx";$postfields='txt_nickname=baluwu&txt_pwd=000000&ddlcookietime='.UrlEncode('一周').'&ibt_login=';$a=request($url,$postfields);unset($postfields,$url);Echo "<textarea style="width:100%;height:200px">",Chr(10),$a,Chr(10),"</textarea>";Die();<br><font color="#e78608">------解决方案--------------------</font><br>http://www.21andy.com/blog/20080507/1095.html<br>看下,或许有帮助<br><font color="#e78608">------解决方案--------------------</font><br>解决这种问题最好的办法就是截包,看看正常的包和curl通信的包有什么不同就知道了<div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1671
14
PHP Tutorial
1276
29
C# Tutorial
1256
24
PHP8.1 released: Introducing curl for concurrent processing of multiple requests PHP8.1 released: Introducing curl for concurrent processing of multiple requests Jul 08, 2023 pm 09:13 PM

PHP8.1 released: Introducing curl for concurrent processing of multiple requests. Recently, PHP officially released the latest version of PHP8.1, which introduced an important feature: curl for concurrent processing of multiple requests. This new feature provides developers with a more efficient and flexible way to handle multiple HTTP requests, greatly improving performance and user experience. In previous versions, handling multiple requests often required creating multiple curl resources and using loops to send and receive data respectively. Although this method can achieve the purpose

From start to finish: How to use php extension cURL to make HTTP requests From start to finish: How to use php extension cURL to make HTTP requests Jul 29, 2023 pm 05:07 PM

From start to finish: How to use php extension cURL for HTTP requests Introduction: In web development, it is often necessary to communicate with third-party APIs or other remote servers. Using cURL to make HTTP requests is a common and powerful way. This article will introduce how to use PHP to extend cURL to perform HTTP requests, and provide some practical code examples. 1. Preparation First, make sure that php has the cURL extension installed. You can execute php-m|grepcurl on the command line to check

Tutorial on updating curl version under Linux! Tutorial on updating curl version under Linux! Mar 07, 2024 am 08:30 AM

To update the curl version under Linux, you can follow the steps below: Check the current curl version: First, you need to determine the curl version installed in the current system. Open a terminal and execute the following command: curl --version This command will display the current curl version information. Confirm available curl version: Before updating curl, you need to confirm the latest version available. You can visit curl's official website (curl.haxx.se) or related software sources to find the latest version of curl. Download the curl source code: Using curl or a browser, download the source code file for the curl version of your choice (usually .tar.gz or .tar.bz2

Where are cookies stored? Where are cookies stored? Dec 20, 2023 pm 03:07 PM

Cookies are usually stored in the cookie folder of the browser. Cookie files in the browser are usually stored in binary or SQLite format. If you open the cookie file directly, you may see some garbled or unreadable content, so it is best to use Use the cookie management interface provided by your browser to view and manage cookies.

Where are the cookies on your computer? Where are the cookies on your computer? Dec 22, 2023 pm 03:46 PM

Cookies on your computer are stored in specific locations on your browser, depending on the browser and operating system used: 1. Google Chrome, stored in C:\Users\YourUsername\AppData\Local\Google\Chrome\User Data\Default \Cookies etc.

How to handle 301 redirection of web pages in PHP Curl? How to handle 301 redirection of web pages in PHP Curl? Mar 08, 2024 am 11:36 AM

How to handle 301 redirection of web pages in PHPCurl? When using PHPCurl to send network requests, you will often encounter a 301 status code returned by the web page, indicating that the page has been permanently redirected. In order to handle this situation correctly, we need to add some specific options and processing logic to the Curl request. The following will introduce in detail how to handle 301 redirection of web pages in PHPCurl, and provide specific code examples. 301 redirect processing principle 301 redirect means that the server returns a 30

Where are the mobile cookies? Where are the mobile cookies? Dec 22, 2023 pm 03:40 PM

Cookies on the mobile phone are stored in the browser application of the mobile device: 1. On iOS devices, Cookies are stored in Settings -> Safari -> Advanced -> Website Data of the Safari browser; 2. On Android devices, Cookies Stored in Settings -> Site settings -> Cookies of Chrome browser, etc.

How cookies work How cookies work Sep 20, 2023 pm 05:57 PM

The working principle of cookies involves the server sending cookies, the browser storing cookies, and the browser processing and storing cookies. Detailed introduction: 1. The server sends a cookie, and the server sends an HTTP response header containing the cookie to the browser. This cookie contains some information, such as the user's identity authentication, preferences, or shopping cart contents. After the browser receives this cookie, it will be stored on the user's computer; 2. The browser stores cookies, etc.

See all articles