CURL有关问题
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>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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

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.

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.

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

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.

The dangers of cookie leakage include theft of personal identity information, tracking of personal online behavior, and account theft. Detailed introduction: 1. Personal identity information is stolen, such as name, email address, phone number, etc. This information may be used by criminals to carry out identity theft, fraud and other illegal activities; 2. Personal online behavior is tracked and analyzed through cookies With the data in the account, criminals can learn about the user's browsing history, shopping preferences, hobbies, etc.; 3. The account is stolen, bypassing login verification, directly accessing the user's account, etc.

With the popularity of the Internet, we use browsers to surf the Internet have become a way of life. In the daily use of browsers, we often encounter situations where we need to enter account passwords, such as online shopping, social networking, emails, etc. This information needs to be recorded by the browser so that it does not need to be entered again the next time you visit. This is when cookies come in handy. What are cookies? Cookie refers to a small data file sent by the server to the user's browser and stored locally. It contains user behavior of some websites.
