PHPcurl – cookies问题
我想通过cUrl自动获取我的amazon关联统计。 然而,我正在倒下的第一个障碍, 在login。
当我使用下面的代码:
$url = 'https://affiliate-program.amazon.com/gp/flex/sign-in/select.html'; $post_data = "action=sign-in&email=$username&password=$password"; $fp = fopen('/my/path/to/cookie.txt', 'w'); fclose($fp); $login = curl_init(); curl_setopt($login, CURLOPT_COOKIESESSION, 1); curl_setopt($login, CURLOPT_COOKIEJAR, '/my/path/to/cookie.txt'); curl_setopt($login, CURLOPT_COOKIEFILE, '/my/path/to/cookie.txt'); curl_setopt($login, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($login, CURLOPT_TIMEOUT, 40); curl_setopt($login, CURLOPT_RETURNTRANSFER, 1); curl_setopt($login, CURLOPT_URL, $url); curl_setopt($login, CURLOPT_HEADER, 1); curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($login, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($login, CURLOPT_POST, 1); curl_setopt($login, CURLOPT_POSTFIELDS, $post_data); echo curl_exec($login); curl_close($login);
我得到以下输出:
HTTP / 1.1 200 OK Date:Thu,22 Sep 2011 22:08:39 GMT Server:Server x-amz-id-1:1NNZMSS8X73EE0G7HKW8 x-amz-id-2:HRW1ZoN4KVzDCp / tS5E7l + 7fn9XGH2k / T7qxzi + WLOw = Set- cookie:session-id-time = 1317279600l; path= /; 域= .amazon.com; expires = Thu Sep 29 07:00:00 2011 GMT Set-cookie:session-id = 181-7755537-2127814; path= /; 域= .amazon.com; expires = Thu Sep 29 07:00:00 2011 GMT变化:Accept-Encoding,User-Agent Cneonction:closuresTransfer-Encoding:chunked Content-Type:text / html; charset = UTF-8请启用Cookies以继续
要继续在Amazon.com购物,请在您的Web浏览器中启用Cookie。 详细了解cookie以及如何启用它们。
一旦您在浏览器中启用了Cookie,请点击下面的button返回上一页。
cookie.txt包含以下内容:
#Netscape HTTP Cookie文件
#http://curl.haxx.se/rfc/cookie_spec.html
#这个文件是由libcurl生成的! 编辑风险自负。
.amazon.com TRUE / FALSE 1317279600 session-id-time 1317279600l
.amazon.com TRUE / FALSE 1317279600 session-id 181-7755537-2127814
实时HTTP标头:
https://affiliate-program.amazon.com/gp/flex/sign-in/select.html
POST /gp/flex/sign-in/select.html HTTP / 1.1主机:
affiliate-program.amazon.com用户代理:Mozilla / 5.0(Windows NT 6.0;
rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
text / html,application / xhtml + xml,application / xml; q = 0.9, / ; q = 0.8
Accept-Language:en-gb,en; q = 0.5 Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive
Referer: https ://affiliate-program.amazon.com/ Cookie:
APN-用户ID = P0000000000; 会话id-时间=1317366000升;
会话id = 182-9139891-5240049;
__utma = 125759317.157031897.1316727783.1316727783.1316795373.2;
__utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无);
ubid-主要= 190-8295480-4625243; __utmv = 125759317.koicarandsup-20;
的x主= QIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9;
在-主= 4 | eaxYjMp + 5TWMiQOn6gROkHUvCfKF3Y9hkvacYbU0 + fzL3Pr1ejcGt78Tb6W5zvUYj67hWyx3AuNd3UparIBCnnrL62d5IMyn7zeFKr7GfjnPvjjaGOPArk7n7tr7go + QgBU6OZ0hKse6MJIdApDrSe2cI0Mz9XDvbumEU5twDKgq338hejMR23IXuWrvq1o0hcfN6DS0oabY7mVIddSMig ==;
__utmb = 125759317; __utmc = 125759317内容types:
application / x-www-form-urlencoded Content-Length:1276
sessionId = 182-9139891-5240049&path =%2Fgp%2Fassociates%2Flogin%2Flogin.html&query = returl%3D%2Fgp%2Fassociates%2Fjoin%2Flanding%2Fmain.html%26retquery%3D&action = sign-in&mode = 1&email = xxx&password = xxx&x = 31&y = 18&metadata1 = xppc1AIU%2Fl8IERp8RJxYooTCV9Vo2Nico9wyEvW9ByghGgc%2FSNU8XqMQnjgshs3DZpFQgLXCAT1qAama%2Bj5WBGxvTRiC45v6Am7hMY99RwJfUIozi5v1ZkwV%2Bcjp9PecvpcPSxLVuwOF4QSf7Q%2BPxNwlxLm5nHXqSNPwmw5Ezg2ENIagMWcrwuDlp50%2B0XKi0e8yyawdc5TjH%2BhGXz12KABRLoH1WuTSwAWleHzGzBUN515WgRMElB583b9h%2FoDINumjmwwsHsjzXjLaEjYaM1w6nw%2F5fqmpABPcN31D7wgDQoOi1xxIyUtZceAa3rwwUxKvpZecStM2T6QtSJhx6YdpLNmHwGSdhkBrsCQVlcLruKNMnUVrb%2FZni3le380YsUeIsVZy113lqayCwla9vwvDTA4mstx2YTKtTU1NOzfblMlYBEL4rhLN1fpeF0EaiAoiatLb1kH%2BCvt6tp78KyPCd0XeEBGqMeDWm2b%2FBSg%2BUqVLBMSeHtJ4VZXxMaWhodZZYU0uxUNwL8hCVruO5KxSbssorByNybuPx%2FmkS87UZMDB62VALgb90MUXLvbVX%2BcmizzBkmwCs3Q6ampHa40NIYQKXTCCnGjVUwavCPv73OrMA8OjVJX3h371m3OHvzpBKRTFG5uiTfZoaaPI%2FYxikE2v99%2FaR3vlwkTZfOhM%2Fba9seIbMpxArTj6ekpmTLbU5LwKn2yVbiAZgsUuFSCNcQMlE%2FJ9nAIuYZ2g uks0Zz%2BPhJ07TOXuTscuc%2Fm0wgqqluPq5NShRINoiGLjiKva6ngslLoQWeKovNwYyVCyNfuwsZ7BIo6%2Fo7yaEfIK6Yb%2BZPMommN%2FI7BFrlW7wrWmaG%2FgbtSx1bg9A5DgtKBDI21j3ibebBZVN%2FP2ZrEB6upCDHEKa1pMCkP6nbOhu%2BxcrNYS%2FyS6e0bv3WiWqugclX%2FnYmBWBdNunCFtI8LKU%2FMvhDT820M%3D
HTTP / 1.1 302 MovedTemporarilydate:2011年9月23日(星期五)16:30:35 GMT
服务器:服务器x-amz-id-1:1JGFY8JCATS8GCJ05WP3 x-amz-id-2:
vNYWJ + 3yN1Qrya1cxENZdlFuZNF4Yc4uYhCmoR3UFBU = Set-Cookie:
在-主= 4 | 3iPYr7E1Pn32BbMI4MHFaMtbn / 0v54qEG1Jn9Pk + 7Hi2Cws1f + jBSUt9oyBzrpy6BX1XCsZ / qoJlbswA0G2U3L9Yhec4CjSlsLZM +的MEPR / AiNAbvuUDzj9wL1HI2x + e7tBqDLhK + fas6R562qkQBX + 9Y7bhE1St11hjislFijGuTcbtr + 5mUz1FuweEFaH / xtHacsJ3Yth9iOiska0CbQ ==;
path= /; 域= .amazon.com; 到期=星期二01月01日08:00:01 2036 GMT;
安全的Set-Cookie:ubid-main = 190-8295480-4625243; path= /;
域= .amazon.com; 到期时间=星期二01月01日08:00:01 2036 GMT地点:
https://affiliate-program.amazon.com/gp/associates/join/landing/main.html
Vary:Accept-Encoding,User-Agent Content-Encoding:gzip nnCoection:
closuresTransfer-Encoding:chunked Content-Type:text / html;
字符集= UTF-8
https://affiliate-program.amazon.com/gp/associates/join/landing/main.html
GET /gp/associates/join/landing/main.html HTTP / 1.1主机:
affiliate-program.amazon.com用户代理:Mozilla / 5.0(Windows NT 6.0;
rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
text / html,application / xhtml + xml,application / xml; q = 0.9, / ; q = 0.8
Accept-Language:en-gb,en; q = 0.5 Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive
Referer: https ://affiliate-program.amazon.com/ Cookie:
APN-用户ID = P0000000000; 会话id-时间=1317366000升;
会话id = 182-9139891-5240049;
__utma = 125759317.157031897.1316727783.1316727783.1316795373.2;
__utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无);
ubid-主要= 190-8295480-4625243; __utmv = 125759317.koicarandsup-20;
的x主= QIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9;
在-主= 4 | 3iPYr7E1Pn32BbMI4MHFaMtbn / 0v54qEG1Jn9Pk + 7Hi2Cws1f + jBSUt9oyBzrpy6BX1XCsZ / qoJlbswA0G2U3L9Yhec4CjSlsLZM +的MEPR / AiNAbvuUDzj9wL1HI2x + e7tBqDLhK + fas6R562qkQBX + 9Y7bhE1St11hjislFijGuTcbtr + 5mUz1FuweEFaH / xtHacsJ3Yth9iOiska0CbQ ==;
__utmb = 125759317; __utmc = 125759317
HTTP / 1.1 302 MovedTemporarilydate:2011年9月23日星期五16:30:36 GMT
服务器:服务器x-amz-id-1:0DVGSNJ16FJ7BZSXKZEA x-amz-id-2:
3zBVVCqaFC6uLEb69n0ImqYEWcveHC / fr3DWJZ9XwfU = Set-Cookie:
ubid-主要= 190-8295480-4625243; path= /; 域= .amazon.com; 期满=星期二
Jan 01 08:00:01 2036 GMT地点:
https://affiliate-program.amazon.com/gp/associates/network/main.html
Vary:Accept-Encoding,User-Agent Content-Encoding:gzip Cneonction:
closuresTransfer-Encoding:chunked Content-Type:text / html;
字符集= UTF-8
https://affiliate-program.amazon.com/gp/associates/network/main.html
GET /gp/associates/network/main.html HTTP / 1.1主机:
affiliate-program.amazon.com用户代理:Mozilla / 5.0(Windows NT 6.0;
rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
text / html,application / xhtml + xml,application / xml; q = 0.9, / ; q = 0.8
Accept-Language:en-gb,en; q = 0.5 Accept-Encoding:gzip,deflate
Accept-Charset:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive
Referer: https ://affiliate-program.amazon.com/ Cookie:
APN-用户ID = P0000000000; 会话id-时间=1317366000升;
会话id = 182-9139891-5240049;
__utma = 125759317.157031897.1316727783.1316727783.1316795373.2;
__utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无);
ubid-主要= 190-8295480-4625243; __utmv = 125759317.koicarandsup-20;
的x主= QIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9;
在-主= 4 | 3iPYr7E1Pn32BbMI4MHFaMtbn / 0v54qEG1Jn9Pk + 7Hi2Cws1f + jBSUt9oyBzrpy6BX1XCsZ / qoJlbswA0G2U3L9Yhec4CjSlsLZM +的MEPR / AiNAbvuUDzj9wL1HI2x + e7tBqDLhK + fas6R562qkQBX + 9Y7bhE1St11hjislFijGuTcbtr + 5mUz1FuweEFaH / xtHacsJ3Yth9iOiska0CbQ ==;
__utmb = 125759317; __utmc = 125759317
HTTP / 1.1 200 OKdate:2011年9月23日星期五16:30:36 GMT服务器:服务器
x-amz-id-1:02WEQDKB29RGKP5T4NWE x-amz-id-2:
xFfF8ncVlxX9KZtDLganiEY4CcDu + qXwkV5CBJGrKWY = Set-Cookie:
ubid-主要= 190-8295480-4625243; path= /; 域= .amazon.com; 期满=星期二
Jan 01 08:00:01 2036 GMT Vary:Accept-Encoding,User-Agent
内容编码:gzip Cneonction:closures传输编码:分块
Content-Type:text / html; 字符集= UTF-8
V192206992.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comG/01/associates/network/thumb-slideshow-widget。V192206992 .jpg
得到
/图像/ G / 01 /联营/networking/拇指幻灯片的小部件。 V192206992 .jpg
HTTP / 1.1主机:images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0
(Windows NT 6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:4119 Last-Modified:
星期三,2010年06月02日17:03:17 GMT内容types:image / jpeg X-Cache-Lookup:
HIT from cdn-images.amazon.com:8080,MISS from
cdn-images.amazon.com:10080 Cache-Control:max-age = 607570264 Date:
星期五,23九月2011 16:30:37 GMT连接:保持活力
SL75.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comI/41WtSRWclnL。SL75 .jpg
GET / images / I / 41WtSRWclnL。 SL75 .jpg HTTP / 1.1主机:
images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0(Windows NT
6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:1317 Last-Modified:
星期四,26五月2011 11:17:40 GMT内容types:image / jpeg X-Cache-Lookup:
HIT from cdn-images.amazon.com:10080 Cache-Control:public,
max-age = 628443948到期时间:星期六,2031年8月23日08:16:25 GMTdate:星期五,23
2011年9月16:30:37 GMT连线:保持活力
SL75.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comI/417XQ0XwQuL。SL75 .jpg
GET / images / I / 417XQ0XwQuL。 SL75 .jpg HTTP / 1.1主机:
images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0(Windows NT
6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:1321 Last-Modified:
星期四,29七月2010 04:26:28 GMT内容types:image / jpegcaching控制:
公共,max-age = 628496714到期时间:2031年8月23日星期六22:55:51 GMTdate:
星期五,23九月2011 16:30:37 GMT连接:保持活力
SL75.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comI/417tb3B43YL。SL75 .jpg
GET / images / I / 417tb3B43YL。 SL75 .jpg HTTP / 1.1主机:
images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0(Windows NT
6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:2462 Last-Modified:
星期五,2009年06月26日04:52:12 GMT内容types:image / jpeg X-Cache-Lookup:
HIT from cdn-images.amazon.com:8080,MISS from
cdn-images.amazon.com:10080 Cache-Control:max-age = 607635331 Date:
星期五,23九月2011 16:30:37 GMT连接:保持活力
SL75.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comI/41sh5uiQ83L。SL75 .jpg
GET / images / I / 41sh5uiQ83L。 SL75 .jpg HTTP / 1.1主机:
images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0(Windows NT
6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:1341 Last-Modified:
星期四,15九月2011 20:05:25 GMT内容types:image / jpeg X-Cache-Lookup:
MISS from cdn-images.amazon.com:10080 Cache-Control:public,
max-age = 630611997有效期至:2031年9月17日星期三10:30:34 GMTdate:星期五,23
2011年9月16:30:37 GMT连线:保持活力
utm.gif?utmwv = 1&utmn = 61668861&utmcs = UTF-8&utmsr = 1280×1024&utmsc = 24位&utmul = EN-GB&utmje = 1&utmfl = 10.3%20r183&utmdt = Amazon.com%20Associates%20Central%20-%20Home&utmhn = affiliate-program.amazon.com&utmr = 0&UTMP = / GP /联营/networking/ main.html中“> https://affiliate-program.amazon.com/_utm.gif?utmwv=1&utmn=61668861&utmcs=UTF-8&utmsr=1280×1024&utmsc=24-bit&utmul=en-gb&utmje = 1&utmfl = 10.3%20r183&utmdt = Amazon.com%20Associates%20Central%20-%20Home&utmhn = affiliate-program.amazon.com&utmr = 0&UTMP = / GP /联营/networking/ main.html中
得到
/__utm.gif?utmwv=1&utmn=61668861&utmcs=UTF-8&utmsr=1280×1024&utmsc=24-bit&utmul=en- gb&utmje = 1&utmfl = 10.3%20r183&utmdt = Amazon.com%20Associates%20Central%20-%20Home&utmhn = affiliate-program.amazon。 COM&utmr = 0&UTMP = / GP /联营/networking/ main.html中
HTTP / 1.1主机:affiliate-program.amazon.com用户代理:Mozilla / 5.0
(Windows NT 6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
Cookie:apn-user-id = P0000000000; 会话id-时间=1317366000升;
会话id = 182-9139891-5240049;
__utma = 125759317.157031897.1316727783.1316727783.1316795373.2;
__utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无);
ubid-主要= 190-8295480-4625243; __utmv = 125759317.koicarandsup-20;
的x主= QIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9;
在-主= 4 | 3iPYr7E1Pn32BbMI4MHFaMtbn / 0v54qEG1Jn9Pk + 7Hi2Cws1f + jBSUt9oyBzrpy6BX1XCsZ / qoJlbswA0G2U3L9Yhec4CjSlsLZM +的MEPR / AiNAbvuUDzj9wL1HI2x + e7tBqDLhK + fas6R562qkQBX + 9Y7bhE1St11hjislFijGuTcbtr + 5mUz1FuweEFaH / xtHacsJ3Yth9iOiska0CbQ ==;
__utmb = 125759317; __utmc = 125759317
HTTP / 1.1 200 OKdate:2011年9月23日星期五16:30:37 GMT服务器:服务器
Last-Modified:Fri,16 Sep 2011 11:22:34 GMT Etag:“23-35b3d280”
Accept-Ranges:bytes Content-Length:35 Cneonction:closures
内容types:image / gif
SL75.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comI/51993R08WLL。SL75 .jpg
GET / images / I / 51993R08WLL。 SL75 .jpg HTTP / 1.1主机:
images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0(Windows NT
6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:1325 Last-Modified:
星期二,27七月2010 16:47:41 GMT内容types:image / jpeg X-Cache-Lookup:
MISS from cdn-images.amazon.com:10080 Cache-Control:public,
max-age = 628244375过期时间:2031年8月21日星期四00:50:12 GMTdate:星期五,23
2011年9月16:30:37 GMT连线:保持活力
SL75.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comI/41is%2B997KUL。SL75 .jpg
GET / images / I / 41is%2B997KUL。 SL75 .jpg HTTP / 1.1主机:
images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0(Windows NT
6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:1662 Last-Modified:
Sun,11 Nov 2007 01:27:41 GMT内容types:image / jpeg X-Cache-Lookup:
MISS from cdn-images.amazon.com:10080 Cache-Control:public,
max-age = 628487843有效期至:2031年8月23日星期六20:28:00 GMTdate:星期五,23
2011年9月16:30:37 GMT连线:保持活力
SL75.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comI/518ISDAvx1L。SL75 .jpg
GET / images / I / 518ISDAvx1L。 SL75 .jpg HTTP / 1.1主机:
images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0(Windows NT
6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:1111 Last-Modified:
星期二,27七月2010 00:37:08 GMT内容types:image / jpeg X-Cache-Lookup:
MISS from cdn-images.amazon.com:10080 Cache-Control:public,
max-age = 628003065有效期至:2031年8月18日星期一05:48:22 GMTdate:星期五,23
2011年9月16:30:37 GMT连线:保持活力
SL75.jpg“> https://images-na.ssl-images-amazon.comhttp://img.dovov.comI/4155OOdySdL。SL75 .jpg
GET / images / I / 4155OOdySdL。 SL75 .jpg HTTP / 1.1主机:
images-na.ssl-images-amazon.com用户代理:Mozilla / 5.0(Windows NT
6.0; rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
HTTP / 1.1 200 OK Server:Server Content-Length:1494 Last-Modified:
星期四,20八月2009 15:52:47 GMT内容types:image / jpeg X-Cache-Lookup:
MISS from cdn-images.amazon.com:10080 Cache-Control:public,
max-age = 630336792到期日:2031年9月14日星期日06:03:49 GMTdate:星期五,23
2011年9月16:30:37 GMT连线:保持活力
utm.gif?utmwv = 1&utmt = VAR&utmn = 1408273993" > https://affiliate-program.amazon.com/_utm.gif?utmwv=1&utmt=var&utmn=1408273993
GET /__utm.gif?utmwv=1&utmt=var&utmn=1408273993 HTTP / 1.1主机:
affiliate-program.amazon.com用户代理:Mozilla / 5.0(Windows NT 6.0;
rv:6.0)Gecko / 20100101 Firefox / 6.0接受:
image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5
Accept-Encoding:gzip,deflate Accept-Charset:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive引用:
https://affiliate-program.amazon.com/gp/associates/network/main.html
Cookie:apn-user-id = P0000000000; 会话id-时间=1317366000升;
会话id = 182-9139891-5240049;
__utma = 125759317.157031897.1316727783.1316727783.1316795373.2;
__utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无);
ubid-主要= 190-8295480-4625243; __utmv = 125759317.koicarandsup-20;
的x主= QIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9;
在-主= 4 | 3iPYr7E1Pn32BbMI4MHFaMtbn / 0v54qEG1Jn9Pk + 7Hi2Cws1f + jBSUt9oyBzrpy6BX1XCsZ / qoJlbswA0G2U3L9Yhec4CjSlsLZM +的MEPR / AiNAbvuUDzj9wL1HI2x + e7tBqDLhK + fas6R562qkQBX + 9Y7bhE1St11hjislFijGuTcbtr + 5mUz1FuweEFaH / xtHacsJ3Yth9iOiska0CbQ ==;
__utmb = 125759317; __utmc = 125759317
HTTP / 1.1 200 OKdate:2011年9月23日星期五16:30:37 GMT服务器:服务器
Last-Modified:Fri,16 Sep 2011 11:22:34 GMT Etag:“23-35b3d280”
Accept-Ranges:bytes Content-Length:35 Cneonction:closures
内容types:image / gif
任何人都可以阐明为什么这不起作用?
编辑:此代码截至2016年6月。请参阅此答案的解释和潜在的解决方法。 上一个链接中提到的技术被添加到了同事的login中。
我写了这个代码,它对我来说很好,在最后的var_dump中,我看到了所有的帐户信息和类似的东西。 如果您不删除这些cookie,则可以使用您的login信息对受保护的页面进行后续的curl请求。
希望这可以帮助你了解如何做到这一点。 很多时候,在大网站上,您需要访问login页面才能设置cookie,并且通常在需要提交的表单上使用csrf标记。
当然,如果亚马逊改变他们的forms或url的话,这将不得不适应一些,但希望他们不要经常这样做。
<?php $email = 'you@yoursite.com'; $password = 'password'; // initial login page which redirects to correct sign in page, sets some cookies $URL = 'https://affiliate-program.amazon.com/gp/associates/join/landing/main.html'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $URL); curl_setopt($ch, CURLOPT_COOKIEJAR, 'amazoncookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'amazoncookie.txt'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); //curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_STDERR, fopen('php://stdout', 'w')); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $page = curl_exec($ch); //var_dump($page);exit; // try to find the actual login form if (!preg_match('/<form name="sign_in".*?<\/form>/is', $page, $form)) { die('Failed to find log in form!'); } $form = $form[0]; // find the action of the login form if (!preg_match('/action=(?:\'|")?([^\s\'">]+)/i', $form, $action)) { die('Failed to find login form url'); } $URL2 = $action[1]; // this is our new post url // find all hidden fields which we need to send with our login, this includes security tokens $count = preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i', $form, $hiddenFields); $postFields = array(); // turn the hidden fields into an array for ($i = 0; $i < $count; ++$i) { $postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i]; } // add our login values $postFields['username'] = $email; $postFields['password'] = $password; $post = ''; // convert to string, this won't work as an array, form will not accept multipart/form-data, only application/x-www-form-urlencoded foreach($postFields as $key => $value) { $post .= $key . '=' . urlencode($value) . '&'; } $post = substr($post, 0, -1); // set additional curl options using our previous options curl_setopt($ch, CURLOPT_URL, $URL2); curl_setopt($ch, CURLOPT_REFERER, $URL); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $page = curl_exec($ch); // make request var_dump($page); // should be logged in
你需要先获得亚马逊的cookie。
尝试:
// 1. Create a cookie file and set basic params $ckfile = tempnam ("/your/path/to/cookie/folder", "cookie.txt"); $target_host = "https://affiliate-program.amazon.com"; $target_request = "/gp/flex/sign-in/select.html"; $post_data = "action=sign-in&email=$username&password=$password"; // 2. Visit homepage to set cookie $ch = curl_init ($target_host); curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec ($ch); // 3. Continue $login = curl_init ($target_host.$target_request); curl_setopt($login, CURLOPT_COOKIESESSION, 1); curl_setopt($login, CURLOPT_COOKIEJAR, $ckfile); curl_setopt($login, CURLOPT_COOKIEFILE, $ckfile); curl_setopt($login, CURLOPT_TIMEOUT, 40); curl_setopt($login, CURLOPT_RETURNTRANSFER, 1); curl_setopt($login, CURLOPT_HEADER, 1); curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($login, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($login, CURLOPT_POST, 1); curl_setopt($login, CURLOPT_POSTFIELDS, $post_data); echo curl_exec($login); curl_close($login);