我正在尝试通过cUrl自动获取我的Amazon Associates统计信息。但是我跌倒了第一关。在登录。
当我使用以下代码时:
$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日期:2011年9月22日星期四22:08:39 GMT服务器:服务器x-amz- id-1:1NNZMSS8X73EE0G7HKW8 x-amz-id-2:HRW1ZoN4KVzDCp / tS5E7l + 7fn9XGH2k / T7qxzi + WLOw = Set- cookie:session-id-time = 1317279600l;路径= /; domain = .amazon.com; expires = Thu Sep 29 07:00:00 2011 GMT Set-cookie:session-id = 181-7755537-2127814; 路径= /; domain = .amazon.com; expires = Thu Sep 29 07:00:00 2011 GMT更改:接受编码,用户代理功能:关闭传输编码:分块内容类型:text / html; charset = UTF-8请启用Cookies以继续 要继续在Amazon.com上购物,请在Web浏览器中启用cookie。了解有关Cookie以及如何启用它们的更多信息。 在浏览器中启用Cookie后,请单击下面的按钮以返回上一页。
HTTP / 1.1 200 OK日期:2011年9月22日星期四22:08:39 GMT服务器:服务器x-amz- id-1:1NNZMSS8X73EE0G7HKW8 x-amz-id-2:HRW1ZoN4KVzDCp / tS5E7l + 7fn9XGH2k / T7qxzi + WLOw = Set- cookie:session-id-time = 1317279600l;路径= /; domain = .amazon.com; expires = Thu Sep 29 07:00:00 2011 GMT Set-cookie:session-id = 181-7755537-2127814; 路径= /; domain = .amazon.com; expires = Thu Sep 29 07:00:00 2011 GMT更改:接受编码,用户代理功能:关闭传输编码:分块内容类型:text / html; charset = UTF-8请启用Cookies以继续
要继续在Amazon.com上购物,请在Web浏览器中启用cookie。了解有关Cookie以及如何启用它们的更多信息。
在浏览器中启用Cookie后,请单击下面的按钮以返回上一页。
cookie.txt包含以下内容:
#Netscape HTTP Cookie文件 http://curl.haxx.se/rfc/cookie_spec.html #此文件由libcurl生成!编辑风险自负。 .amazon.com是/否1317279600会话ID时间1317279600l .amazon.com是/否1317279600 session-id 181-7755537-2127814
#Netscape HTTP Cookie文件
#此文件由libcurl生成!编辑风险自负。
.amazon.com是/否1317279600会话ID时间1317279600l
.amazon.com是/否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 接受语言:en-gb,en; q = 0.5接受编码:gzip,deflate 接受字符集:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive 推荐人:https://affiliate- program.amazon.com/ Cookie: apn-user-id = P0000000000; session-id-time = 1317366000l; session-id = 182-9139891-5240049; __utma = 125759317.157031897.1316727783.1316727783.1316795373.2; __utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无); ubid-main = 190-8295480-4625243; __utmv = 125759317.koicarandsup-20; x-main = qIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9; 在-主= 4 | eaxYjMp + 5TWMiQOn6gROkHUvCfKF3Y9hkvacYbU0 + fzL3Pr1ejcGt78Tb6W5zvUYj67hWyx3AuNd3UparIBCnnrL62d5IMyn7zeFKr7GfjnPvjjaGOPArk7n7tr7go + QgBU6OZ0hKse6MJIdApDrSe2cI0Mz9XDvbumEU5twDKgq338hejMR23IXuWrvq1o0hcfN6DS0oabY7mVIddSMig ==; __utmb = 125759317; __utmc = 125759317内容类型: application / x-www-form-urlencoded内容长度: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 = 18&metadata1 = xppc1AIU%2Fl8IERp8RJxYooTCV9Vo2Nico9wyEvW9ByghGgc%2FSNU8XqMQnjgshs3DZpFQgLXCAT1qAama%2Bj5WBGxvTRiC45v6Am7hMY99RwJfUIozi5v1ZkwV%2Bcjp9PecvpcPSxLVuwOF4QSf7Q%2BPxNwlxLm5nHXqSNPwmw5Ezg2ENIagMWcrwuDlp50%2B0XKi0e8yyawdc5TjH%2BhGXz12KABRLoH1WuTSwAWleHzGzBUN515WgRMElB583b9h%2FoDINumjmwwsHsjzXjLaEjYaM1w6nw%2F5fqmpABPcN31D7wgDQoOi1xxIyUtZceAa3rwwUxKvpZecStM2T6QtSJhx6YdpLNmHwGSdhkBrsCQVlcLruKNMnUVrb%2FZni3le380YsUeIsVZy113lqayCwla9vwvDTA4mstx2YTKtTU1NOzfblMlYBEL4rhLN1fpeF0EaiAoiatLb1kH%2BCvt6tp78KyPCd0XeEBGqMeDWm2b%2FBSg%2BUqVLBMSeHtJ4VZXxMaWhodZZYU0uxUNwL8hCVruO5KxSbssorByNybuPx%2FmkS87UZMDB62VALgb90MUXLvbVX%2BcmizzBkmwCs3Q6ampHa40NIYQKXTCCnGjVUwavCPv73OrMA8OjVJX3h371m3OHvzpBKRTFG5uiTfZoaaPI%2FYxikE2v99%2FaR3vlwkTZfOhM%2Fba9seIbMpxArTj6ekpmTLbU5LwKn2yVbiAZgsUuFSCNcQMlE%2FJ9nAIuYZ2guks0Zz%2BPhJ07TOXuTscuc%2Fm0wgqqluPq5NShRINoiGLjiKva6ngslLoQWeKovNwYyVCyNfuwsZ7BIo6%2Fo7yaEfIK6Yb%2BZPMommN%2FI7BFrlW7wrWmaG%2FgbtSx1bg9A5DgtKBDI21j3ibebBZVN%2FP2ZrEB6upCDHEKa1pMCkPvnNYSY2%3B HTTP / 1.1 302已移动临时日期:2011年9月23日星期五,格林尼治标准时间 服务器:服务器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 ==; 路径= /; domain = .amazon.com; expires =星期二1月1日08:00:01 2036 GMT; 安全Set-Cookie:ubid-main = 190-8295480-4625243; 路径= /; domain = .amazon.com; expires = Tue Jan 01 08:00:01 2036 GMT位置: https://affiliate-program.amazon.com/gp/associates/join/landing/main.html 不同:接受编码,用户代理内容编码:gzip nn功能: close传输编码:分块内容类型: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 接受语言:en-gb,en; q = 0.5接受编码:gzip,deflate 接受字符集:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive 推荐人:https://affiliate- program.amazon.com/ Cookie: apn-user-id = P0000000000; session-id-time = 1317366000l; session-id = 182-9139891-5240049; __utma = 125759317.157031897.1316727783.1316727783.1316795373.2; __utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无); ubid-main = 190-8295480-4625243; __utmv = 125759317.koicarandsup-20; x-main = qIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9; 在-主= 4 | 3iPYr7E1Pn32BbMI4MHFaMtbn / 0v54qEG1Jn9Pk + 7Hi2Cws1f + jBSUt9oyBzrpy6BX1XCsZ / qoJlbswA0G2U3L9Yhec4CjSlsLZM +的MEPR / AiNAbvuUDzj9wL1HI2x + e7tBqDLhK + fas6R562qkQBX + 9Y7bhE1St11hjislFijGuTcbtr + 5mUz1FuweEFaH / xtHacsJ3Yth9iOiska0CbQ ==; __utmb = 125759317; __utmc = 125759317 HTTP / 1.1 302已移动临时日期:2011年9月23日星期五,格林尼治标准时间 服务器:服务器x-amz-id-1:0DVGSNJ16FJ7BZSXKZEA x-amz-id-2: 3zBVVCqaFC6uLEb69n0ImqYEWcveHC / fr3DWJZ9XwfU = Set-Cookie: ubid-main = 190-8295480-4625243; 路径= /; domain = .amazon.com; expires =星期二 1月1日08:00:01 2036 GMT位置: https://affiliate-program.amazon.com/gp/associates/network/main.html 不同:接受编码,用户代理内容编码:gzip功能: close传输编码:分块内容类型: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 接受语言:en-gb,en; q = 0.5接受编码:gzip,deflate 接受字符集:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive 推荐人:https://affiliate- program.amazon.com/ Cookie: apn-user-id = P0000000000; session-id-time = 1317366000l; session-id = 182-9139891-5240049; __utma = 125759317.157031897.1316727783.1316727783.1316795373.2; __utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无); ubid-main = 190-8295480-4625243; __utmv = 125759317.koicarandsup-20; x-main = qIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9; 在-主= 4 | 3iPYr7E1Pn32BbMI4MHFaMtbn / 0v54qEG1Jn9Pk + 7Hi2Cws1f + jBSUt9oyBzrpy6BX1XCsZ / qoJlbswA0G2U3L9Yhec4CjSlsLZM +的MEPR / AiNAbvuUDzj9wL1HI2x + e7tBqDLhK + fas6R562qkQBX + 9Y7bhE1St11hjislFijGuTcbtr + 5mUz1FuweEFaH / xtHacsJ3Yth9iOiska0CbQ ==; __utmb = 125759317; __utmc = 125759317 HTTP / 1.1 200 OK日期:2011年9月23日星期五,格林尼治标准时间30:36服务器:服务器 x-amz-id-1:02WEQDKB29RGKP5T4NWE x-amz-id-2: xFfF8ncVlxX9KZtDLganiEY4CcDu + qXwkV5CBJGrKWY = Set-Cookie: ubid-main = 190-8295480-4625243; 路径= /; domain = .amazon.com; expires =星期二 1月1日08:00:01 2036 GMT变化:接受编码,用户代理 内容编码:gzip功能:关闭传输编码:分块 内容类型:text / html; 字符集= UTF-8 V192206992.jpg“> https://images-na.ssl-images- amazon.com/images/G/01/associates/network/thumb-slideshow-widget。 V192206992 .JPG 得到 /images/G/01/associates/network/thumb-slideshow-widget. 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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:4119上次修改时间: 2010年6月2日星期三17:03:17 GMT内容类型:image / jpeg X-Cache-Lookup: 来自cdn-images.amazon.com的HIT:8080,来自的MISS cdn-images.amazon.com:10080缓存控制:max-age = 607570264日期: 2011年9月23日星期五,格林尼治标准时间16:30:37连接:保持活动状态 SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:1317上次修改时间: 2011年5月26日,星期四,格林尼治标准时间内容类型:image / jpeg X-Cache-Lookup: 来自cdn-images.amazon.com的HIT:10080缓存控制:公共, max-age = 628443948过期:2031年8月23日星期六08:16:25 GMT日期:23日星期五 2011年9月16日30:37 GMT连接:保持活动状态 SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:1321上次修改时间: 2010年7月29日,星期四,04:26:28 GMT内容类型:image / jpeg缓存控制: public,max-age = 628496714过期:2031年8月23日星期六22:55:51 GMT日期: 2011年9月23日星期五,格林尼治标准时间16:30:37连接:保持活动状态 SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:2462最后修改时间: 2009年6月26日,星期五,格林尼治标准时间04:52:12内容类型:image / jpeg X-Cache-Lookup: 来自cdn-images.amazon.com的HIT:8080,来自的MISS cdn-images.amazon.com:10080缓存控制:max-age = 607635331日期: 2011年9月23日星期五,格林尼治标准时间16:30:37连接:保持活动状态 SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:1341最后修改时间: Thu,15 Sep 2011 20:05:25 GMT内容类型:image / jpeg X-Cache-Lookup: 来自cdn-images.amazon.com的MISS:10080缓存控制:公共, max-age = 630611997过期:2031年9月17日星期三10:30:34 GMT日期:23日星期五 2011年9月16日30:37 GMT连接:保持活动状态 utm.gif?utmwv = 1&utmn = 61668861&utmcs = UTF-8&utmsr = 1280x1024&utmsc = 24-bit&utmul = en-gb&utmje = 1&utmfl = 10.3%20r183&utmdt = Amazon.com%20Associates%20Central%20-%20Home&utmhn = affili。 = 0&utmp = / gp / associates / network / main.html“> https://affiliate- program.amazon.com/_utm.gif?utmwv=1&utmn=61668861&utmcs=UTF-8&utmsr=1280x1024&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 / associates / network / main.html 得到 /__utm.gif?utmwv=1&utmn=61668861&utmcs=UTF-8&utmsr=1280x1024&utmsc=24位&utmul = en- gb&utmje = 1&utmfl = 10.3%20r183&utmdt = Amazon.com%20Associates%20Central%20-%20Home&utmhn = aff。 com&utmr = 0&utmp = / 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接受: image / png,image / ; q = 0.8, /* ;q=0.5 Accept-Language:en-gb,en; q = 0.5 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html Cookie:apn-user-id = P0000000000; session-id-time = 1317366000l; session-id = 182-9139891-5240049; __utma = 125759317.157031897.1316727783.1316727783.1316795373.2; __utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无); ubid-main = 190-8295480-4625243; __utmv = 125759317.koicarandsup-20; x-main = qIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9; 在-主= 4 | 3iPYr7E1Pn32BbMI4MHFaMtbn / 0v54qEG1Jn9Pk + 7Hi2Cws1f + jBSUt9oyBzrpy6BX1XCsZ / qoJlbswA0G2U3L9Yhec4CjSlsLZM +的MEPR / AiNAbvuUDzj9wL1HI2x + e7tBqDLhK + fas6R562qkQBX + 9Y7bhE1St11hjislFijGuTcbtr + 5mUz1FuweEFaH / xtHacsJ3Yth9iOiska0CbQ ==; __utmb = 125759317; __utmc = 125759317 HTTP / 1.1 200 OK日期:2011年9月23日星期五,格林尼治标准时间30:37服务器:服务器 上次修改时间:2011年9月16日,星期五,格林尼治标准时间Etag:“ 23-35b3d280” 接受范围:字节内容长度:35连接:关闭 内容类型:图片/ gif SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:1325上次修改时间: Tue,27 Jul 2010 16:47:41 GMT内容类型:image / jpeg X-Cache-Lookup: 来自cdn-images.amazon.com的MISS:10080缓存控制:公共, max-age = 628244375过期:2031年8月21日,星期四00:50:12 GMT日期:23日,星期五 2011年9月16日30:37 GMT连接:保持活动状态 SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:1662最后修改时间: Sun,11 Nov 2007 01:27:41 GMT内容类型:image / jpeg X-Cache-Lookup: 来自cdn-images.amazon.com的MISS:10080缓存控制:公共, max-age = 628487843到期时间:2031年8月23日星期六20:28:00 GMT日期:23日星期五 2011年9月16日30:37 GMT连接:保持活动状态 SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:1111上次修改时间: Tue,27 Jul 2010 00:37:08 GMT内容类型:image / jpeg X-Cache-Lookup: 来自cdn-images.amazon.com的MISS:10080缓存控制:公共, max-age = 628003065过期:2031年8月18日星期一05:48:22 GMT日期:23日星期五 2011年9月16日30:37 GMT连接:保持活动状态 SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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 接受编码:gzip,缩小接受字符集: ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址: https://affiliate-program.amazon.com/gp/associates/network/main.html HTTP / 1.1 200 OK服务器:服务器内容长度:1494最后修改时间: Thu,2009年8月20日15:52:47 GMT内容类型:image / jpeg X-Cache-Lookup: MISS from cdn-images.amazon.com:10080 Cache-Control: public, max-age=630336792 Expires: Sun, 14 Sep 2031 06:03:49 GMT Date: Fri, 23 Sep 2011 16:30:37 GMT Connection: keep-alive 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 Host: affiliate-program.amazon.com User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:6.0) Gecko/20100101 Firefox/6.0 Accept: 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 Connection: keep-alive Referer: https://affiliate-program.amazon.com/gp/associates/network/main.html Cookie: apn-user-id=P0000000000; session-id-time=1317366000l; session-id=182-9139891-5240049; __utma=125759317.157031897.1316727783.1316727783.1316795373.2; __utmz=125759317.1316727783.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none); ubid-main=190-8295480-4625243; __utmv=125759317.koicarandsup-20; x-main=qIM@jFtaFnr4KaiFFutR7WZ1QkQHqoq9; at- main=4|3iPYr7E1Pn32BbMI4MHFaMtbn/0v54qEG1Jn9Pk+7Hi2Cws1f+jBSUt9oyBzrpy6BX1XCsZ/qoJlbswA0G2U3L9Yhec4CjSlsLZM+mEPRs/AiNAbvuUDzj9wL1HI2x+e7tBqDLhK+fas6R562qkQBX+9Y7bhE1St11hjislFijGuTcbtr+5mUz1FuweEFaH/xtHacsJ3Yth9iOiska0CbQ==; __utmb=125759317; __utmc=125759317 HTTP/1.1 200 OK Date: Fri, 23 Sep 2011 16:30:37 GMT Server: Server Last-Modified: Fri, 16 Sep 2011 11:22:34 GMT Etag: “23-35b3d280” Accept-Ranges: bytes Content-Length: 35 Cneonction: close Content-Type: image/gif
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
接受语言:en-gb,en; q = 0.5接受编码:gzip,deflate
接受字符集:ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:keep-alive
推荐人:https://affiliate- program.amazon.com/ Cookie:
apn-user-id = P0000000000; session-id-time = 1317366000l;
session-id = 182-9139891-5240049;
__utma = 125759317.157031897.1316727783.1316727783.1316795373.2;
__utmz = 125759317.1316727783.1.1.utmccn =(直接)| utmcsr =(直接)| utmcmd =(无);
ubid-main = 190-8295480-4625243; __utmv = 125759317.koicarandsup-20;
x-main = qIM @ jFtaFnr4KaiFFutR7WZ1QkQHqoq9;
在-主= 4 | eaxYjMp + 5TWMiQOn6gROkHUvCfKF3Y9hkvacYbU0 + fzL3Pr1ejcGt78Tb6W5zvUYj67hWyx3AuNd3UparIBCnnrL62d5IMyn7zeFKr7GfjnPvjjaGOPArk7n7tr7go + QgBU6OZ0hKse6MJIdApDrSe2cI0Mz9XDvbumEU5twDKgq338hejMR23IXuWrvq1o0hcfN6DS0oabY7mVIddSMig ==;
__utmb = 125759317; __utmc = 125759317内容类型:
application / x-www-form-urlencoded内容长度: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 = 18&metadata1 = xppc1AIU%2Fl8IERp8RJxYooTCV9Vo2Nico9wyEvW9ByghGgc%2FSNU8XqMQnjgshs3DZpFQgLXCAT1qAama%2Bj5WBGxvTRiC45v6Am7hMY99RwJfUIozi5v1ZkwV%2Bcjp9PecvpcPSxLVuwOF4QSf7Q%2BPxNwlxLm5nHXqSNPwmw5Ezg2ENIagMWcrwuDlp50%2B0XKi0e8yyawdc5TjH%2BhGXz12KABRLoH1WuTSwAWleHzGzBUN515WgRMElB583b9h%2FoDINumjmwwsHsjzXjLaEjYaM1w6nw%2F5fqmpABPcN31D7wgDQoOi1xxIyUtZceAa3rwwUxKvpZecStM2T6QtSJhx6YdpLNmHwGSdhkBrsCQVlcLruKNMnUVrb%2FZni3le380YsUeIsVZy113lqayCwla9vwvDTA4mstx2YTKtTU1NOzfblMlYBEL4rhLN1fpeF0EaiAoiatLb1kH%2BCvt6tp78KyPCd0XeEBGqMeDWm2b%2FBSg%2BUqVLBMSeHtJ4VZXxMaWhodZZYU0uxUNwL8hCVruO5KxSbssorByNybuPx%2FmkS87UZMDB62VALgb90MUXLvbVX%2BcmizzBkmwCs3Q6ampHa40NIYQKXTCCnGjVUwavCPv73OrMA8OjVJX3h371m3OHvzpBKRTFG5uiTfZoaaPI%2FYxikE2v99%2FaR3vlwkTZfOhM%2Fba9seIbMpxArTj6ekpmTLbU5LwKn2yVbiAZgsUuFSCNcQMlE%2FJ9nAIuYZ2guks0Zz%2BPhJ07TOXuTscuc%2Fm0wgqqluPq5NShRINoiGLjiKva6ngslLoQWeKovNwYyVCyNfuwsZ7BIo6%2Fo7yaEfIK6Yb%2BZPMommN%2FI7BFrlW7wrWmaG%2FgbtSx1bg9A5DgtKBDI21j3ibebBZVN%2FP2ZrEB6upCDHEKa1pMCkPvnNYSY2%3B
HTTP / 1.1 302已移动临时日期:2011年9月23日星期五,格林尼治标准时间
服务器:服务器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 ==;
路径= /; domain = .amazon.com; expires =星期二1月1日08:00:01 2036 GMT;
安全Set-Cookie:ubid-main = 190-8295480-4625243; 路径= /;
domain = .amazon.com; expires = Tue Jan 01 08:00:01 2036 GMT位置:
https://affiliate-program.amazon.com/gp/associates/join/landing/main.html
不同:接受编码,用户代理内容编码:gzip nn功能:
close传输编码:分块内容类型: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主机:
__utmb = 125759317; __utmc = 125759317
服务器:服务器x-amz-id-1:0DVGSNJ16FJ7BZSXKZEA x-amz-id-2:
3zBVVCqaFC6uLEb69n0ImqYEWcveHC / fr3DWJZ9XwfU = Set-Cookie:
ubid-main = 190-8295480-4625243; 路径= /; domain = .amazon.com; expires =星期二
1月1日08:00:01 2036 GMT位置:
https://affiliate-program.amazon.com/gp/associates/network/main.html
不同:接受编码,用户代理内容编码:gzip功能:
https://affiliate- program.amazon.com/gp/associates/network/main.html
GET /gp/associates/network/main.html HTTP / 1.1主机:
HTTP / 1.1 200 OK日期:2011年9月23日星期五,格林尼治标准时间30:36服务器:服务器
x-amz-id-1:02WEQDKB29RGKP5T4NWE x-amz-id-2:
xFfF8ncVlxX9KZtDLganiEY4CcDu + qXwkV5CBJGrKWY = Set-Cookie:
1月1日08:00:01 2036 GMT变化:接受编码,用户代理
内容编码:gzip功能:关闭传输编码:分块
内容类型:text / html; 字符集= UTF-8
V192206992.jpg“> https://images-na.ssl-images- amazon.com/images/G/01/associates/network/thumb-slideshow-widget。 V192206992 .JPG
得到
/images/G/01/associates/network/thumb-slideshow-widget. 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
接受编码:gzip,缩小接受字符集:
ISO-8859-1,utf-8; q = 0.7,*; q = 0.7连接:保持活动引用地址:
HTTP / 1.1 200 OK服务器:服务器内容长度:4119上次修改时间:
2010年6月2日星期三17:03:17 GMT内容类型:image / jpeg X-Cache-Lookup:
来自cdn-images.amazon.com的HIT:8080,来自的MISS
cdn-images.amazon.com:10080缓存控制:max-age = 607570264日期:
2011年9月23日星期五,格林尼治标准时间16:30:37连接:保持活动状态
SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/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接受:
HTTP / 1.1 200 OK服务器:服务器内容长度:1317上次修改时间:
2011年5月26日,星期四,格林尼治标准时间内容类型:image / jpeg X-Cache-Lookup:
来自cdn-images.amazon.com的HIT:10080缓存控制:公共,
max-age = 628443948过期:2031年8月23日星期六08:16:25 GMT日期:23日星期五
2011年9月16日30:37 GMT连接:保持活动状态
SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/417XQ0XwQuL。 SL75 .JPG
GET / images / I / 417XQ0XwQuL。 SL75 .jpg HTTP / 1.1主机:
HTTP / 1.1 200 OK服务器:服务器内容长度:1321上次修改时间:
2010年7月29日,星期四,04:26:28 GMT内容类型:image / jpeg缓存控制:
public,max-age = 628496714过期:2031年8月23日星期六22:55:51 GMT日期:
SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/417tb3B43YL。 SL75 .JPG
GET / images / I / 417tb3B43YL。 SL75 .jpg HTTP / 1.1主机:
HTTP / 1.1 200 OK服务器:服务器内容长度:2462最后修改时间:
2009年6月26日,星期五,格林尼治标准时间04:52:12内容类型:image / jpeg X-Cache-Lookup:
cdn-images.amazon.com:10080缓存控制:max-age = 607635331日期:
SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/41sh5uiQ83L。 SL75 .JPG
GET / images / I / 41sh5uiQ83L。 SL75 .jpg HTTP / 1.1主机:
HTTP / 1.1 200 OK服务器:服务器内容长度:1341最后修改时间:
Thu,15 Sep 2011 20:05:25 GMT内容类型:image / jpeg X-Cache-Lookup:
来自cdn-images.amazon.com的MISS:10080缓存控制:公共,
max-age = 630611997过期:2031年9月17日星期三10:30:34 GMT日期:23日星期五
utm.gif?utmwv = 1&utmn = 61668861&utmcs = UTF-8&utmsr = 1280x1024&utmsc = 24-bit&utmul = en-gb&utmje = 1&utmfl = 10.3%20r183&utmdt = Amazon.com%20Associates%20Central%20-%20Home&utmhn = affili。 = 0&utmp = / gp / associates / network / main.html“> https://affiliate- program.amazon.com/_utm.gif?utmwv=1&utmn=61668861&utmcs=UTF-8&utmsr=1280x1024&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 / associates / network / main.html
/__utm.gif?utmwv=1&utmn=61668861&utmcs=UTF-8&utmsr=1280x1024&utmsc=24位&utmul = en- gb&utmje = 1&utmfl = 10.3%20r183&utmdt = Amazon.com%20Associates%20Central%20-%20Home&utmhn = aff。 com&utmr = 0&utmp = / gp / associates / network / main.html
HTTP / 1.1主机:affiliate-program.amazon.com用户代理:Mozilla / 5.0
Cookie:apn-user-id = P0000000000; session-id-time = 1317366000l;
HTTP / 1.1 200 OK日期:2011年9月23日星期五,格林尼治标准时间30:37服务器:服务器
上次修改时间:2011年9月16日,星期五,格林尼治标准时间Etag:“ 23-35b3d280”
接受范围:字节内容长度:35连接:关闭
内容类型:图片/ gif
SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/51993R08WLL。 SL75 .JPG
GET / images / I / 51993R08WLL。 SL75 .jpg HTTP / 1.1主机:
HTTP / 1.1 200 OK服务器:服务器内容长度:1325上次修改时间:
Tue,27 Jul 2010 16:47:41 GMT内容类型:image / jpeg X-Cache-Lookup:
max-age = 628244375过期:2031年8月21日,星期四00:50:12 GMT日期:23日,星期五
SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/41is%2B997KUL。 SL75 .JPG
GET / images / I / 41is%2B997KUL。 SL75 .jpg HTTP / 1.1主机:
HTTP / 1.1 200 OK服务器:服务器内容长度:1662最后修改时间:
Sun,11 Nov 2007 01:27:41 GMT内容类型:image / jpeg X-Cache-Lookup:
max-age = 628487843到期时间:2031年8月23日星期六20:28:00 GMT日期:23日星期五
SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/518ISDAvx1L。 SL75 .JPG
GET / images / I / 518ISDAvx1L。 SL75 .jpg HTTP / 1.1主机:
HTTP / 1.1 200 OK服务器:服务器内容长度:1111上次修改时间:
Tue,27 Jul 2010 00:37:08 GMT内容类型:image / jpeg X-Cache-Lookup:
max-age = 628003065过期:2031年8月18日星期一05:48:22 GMT日期:23日星期五
SL75.jpg“> https://images-na.ssl-images-amazon.com/images/I/4155OOdySdL。 SL75 .JPG
GET / images / I / 4155OOdySdL。 SL75 .jpg HTTP / 1.1主机:
HTTP / 1.1 200 OK服务器:服务器内容长度:1494最后修改时间:
Thu,2009年8月20日15:52:47 GMT内容类型:image / jpeg X-Cache-Lookup:
MISS from cdn-images.amazon.com:10080 Cache-Control: public,
max-age=630336792 Expires: Sun, 14 Sep 2031 06:03:49 GMT Date: Fri, 23
Sep 2011 16:30:37 GMT Connection: keep-alive
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 Host:
affiliate-program.amazon.com User-Agent: Mozilla/5.0 (Windows NT 6.0;
rv:6.0) Gecko/20100101 Firefox/6.0 Accept:
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 Connection: keep-alive Referer:
Cookie: apn-user-id=P0000000000; session-id-time=1317366000l;
session-id=182-9139891-5240049;
__utma=125759317.157031897.1316727783.1316727783.1316795373.2;
__utmz=125759317.1316727783.1.1.utmccn=(direct)|utmcsr=(direct)|utmcmd=(none);
ubid-main=190-8295480-4625243; __utmv=125759317.koicarandsup-20;
x-main=qIM@jFtaFnr4KaiFFutR7WZ1QkQHqoq9;
at- main=4|3iPYr7E1Pn32BbMI4MHFaMtbn/0v54qEG1Jn9Pk+7Hi2Cws1f+jBSUt9oyBzrpy6BX1XCsZ/qoJlbswA0G2U3L9Yhec4CjSlsLZM+mEPRs/AiNAbvuUDzj9wL1HI2x+e7tBqDLhK+fas6R562qkQBX+9Y7bhE1St11hjislFijGuTcbtr+5mUz1FuweEFaH/xtHacsJ3Yth9iOiska0CbQ==;
__utmb=125759317; __utmc=125759317
HTTP/1.1 200 OK Date: Fri, 23 Sep 2011 16:30:37 GMT Server: Server
Last-Modified: Fri, 16 Sep 2011 11:22:34 GMT Etag: “23-35b3d280”
Accept-Ranges: bytes Content-Length: 35 Cneonction: close
Content-Type: image/gif
Can anyone shed some light on why this is not working?
我写了这段代码,它对我很好,在上一个var_dump中我看到了我的账户信息之类的。如果你不删除cookies,你可以使用登录名对受保护的页面发出后续curl请求。
希望这能帮助你学会如何去做。很多时候您需要访问登录页才能设置cookies的站点,以及通常在需要提交的表单上有csrf令牌。
当然,如果amazon稍微更改了表单或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