PHP Curl - Cookie 问题

发布于 2024-12-06 05:08:00 字数 22069 浏览 0 评论 0原文

我正在尝试通过 cUrl 自动获取我的亚马逊同事统计信息。然而,我在第一道坎就跌倒了; 当我使用

以下代码时:

    $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= 设置cookie: 会话 ID 时间=1317279600l;路径=/;域名=.amazon.com;到期=周四 2011 年 9 月 29 日 07:00:00 GMT Set-cookie: session-id=181-7755537-2127814; 路径=/;域名=.amazon.com;过期= 2011 年 9 月 29 日星期四 07:00:00 GMT 变化: Accept-Encoding,User-Agent Cneonction: 关闭 Transfer-Encoding: 分块内容类型:text/html; charset=UTF-8 请启用 Cookie 继续

要继续在 Amazon.com 购物,请在您的网站中启用 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 会话 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 连接:保持活动

引荐来源:https://affiliate-program.amazon.com/ Cookie:

apn-用户-id=P0000000000; session-id-time=1317366000l;

会话 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;

at-main=4|eaxYjMp+5TWMiQOn6gROkHUvCfKF3Y9hkvacYbU0+fzL3Pr1ejcGt78Tb6W5zvUYj67hWyx3AuNd3UparIBCnnrL62d5IMyn7zeFKr7G fjnPvjjaGOPArk7n7tr7go+QgBU6OZ0hKse6MJIdApDrSe2cI0Mz9XDvbumEU5twDKgq338hejMR23IXuWrvq1o0hcfN6DS0oabY7mVIddSMig==;

__utmb=125759317; __utmc=125759317 内容类型:

application/x-www-form-urlencoded 内容长度:1276

会话 ID=182-9139891- 5240049&路径=%2Fgp%2Fassociates%2Flogin%2Flogin.html&query=returl%3D%2Fgp%2Fassociates%2Fjoin%2Flanding%2Fmain.html%26retquery%3D&action=登录&a mp;模式=1&电子邮件=xxx&密码=xxx&x=31&y=18&元数据1=xppc1AIU%2Fl8IERp8RJxYooTCV9Vo2Nico9wyEvW9ByghGgc%2FSNU8XqMQnjgshs3DZpFQgLXCAT1qAama%2 BJ5WBGxvTRiC45v6Am7hMY99RwJfUIozi5v1ZkwV%2Bcjp9PecvpcPSxLVuwOF4QSf7Q%2BPxNwlxLm 5nHXqSNPwmw5Ezg2ENIagMWcrwuDlp50%2B0XKi0e8yyawdc5TjH%2BhGXz12KABRLoH1WuTSwaWleH zGzBUN515WgRMElB583b9h%2FoDINumjmwwsHsjzXjLaEjYaM1w6nw%2F5fqmpABPcN31D7wgDQoOi1 xxIyUtZceAa3rwwUxKvpZecStM2T6QtSJhx6YdpLNmHwGSdhkBrsCQVlcLruKNMnUVrb%2FZni3le380 YsUeIsVZy113lqayCwla9vwvDTA4mstx2YTKtTU1NOzfblMlyBEL4rhLN1fpeF0EaiAoiatLb1kH%2B Cvt6tp78KyPCd0XeEBGqMeDWm2b%2FBSg%2BUqVLBMSeHtJ4VZXxMaWhodZZYU0uxUNwL8hCVruO5Kx SbssorByNybuPx%2FmkS87UZMDB62VALgb90MUXLvbVX%2BcmizzBkmwCs3Q6ampHa40NIYQKXTCCnG jVUwavCPv73OrMA8OjVJX3h371m3OHvzpBKRTFG5uiTfZoaaPI%2FYxikE2v99%2FaR3vlwkTZfOhM%2 Fba9seIbMpxArTj6ekpmTLbU5LwKn2yVbiAZgsUuFSCNcQMlE%2FJ9nAIuYZ2guks0Zz%2BPhJ07TOX utscuc%2Fm0wgqqluPq5NShRINoiGLjiKva6ngslLoQWeKovNwYyVCyNfuwsZ7BIo6%2Fo7yaEfIK6Yb %2BZPMommN%2FI7BFrlW7wrWmaG%2FgbtSx1bg9A5DgtKBDI21j3ibebBZVN%2FP2ZrEB6upCDHEKa1 pMCkP6nbOhu%2BxcrNYS%2FyS6e0bv3WiWqugclX%2FnYmBWBdNunCFtI8LKU%2FMvhDT820M%3D

HTTP/1.1 302 暂时移动日期:2011 年 9 月 23 日星期五 16:30:35 GMT

服务器:服务器 x-amz-id-1:1JGFY8JCATS8GCJ05WP3 x-amz-id-2:

vNYWJ+3yN1Qrya1cxENZdlFuZNF4Yc4uYhCmoR3UFBU= 设置 Cookie:

at-main=4|3iPYr7E1Pn32BbMI4MHFaMtbn/0v54qEG1Jn9Pk+7Hi2Cws1f+jBSUt9oyBzrpy6BX1XCsZ/qoJlbswA0G2U3L9Yhec4CjSlsLZM+mEP Rs/AiNAbvuUDzj9wL1HI2x+e7tBqDLhK+fas6R562qkQBX+9Y7bhE1St11hjislFijGuTcbtr+5mUz1FuweEFaH/xtHacsJ3Yth9iOiska0CbQ==;

路径=/;域名=.amazon.com;过期=格林尼治标准时间 2036 年 1 月 1 日星期二 08:00:01;

安全设置 Cookie:ubid-main=190-8295480-4625243;路径=/;

域名=.amazon.com;过期=2036 年格林威治标准时间 (GMT) 星期二 1 月 1 日 08:00:01 位置:

https://affiliate-program.amazon.com/gp/associates/join /landing/main.html

变化:接受编码,用户代理内容编码:gzip nnCoection:

关闭传输编码:分块内容类型: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 连接:保持活动

引荐来源:https://affiliate-program.amazon.com/ Cookie:

apn-用户-id=P0000000000; session-id-time=1317366000l;

会话 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;

at-main=4|3iPYr7E1Pn32BbMI4MHFaMtbn/0v54qEG1Jn9Pk+7Hi2Cws1f+jBSUt9oyBzrpy6BX1XCsZ/qoJlbswA0G2U3L9Yhec4CjSlsLZM+mEP Rs/AiNAbvuUDzj9wL1HI2x+e7tBqDLhK+fas6R562qkQBX+9Y7bhE1St11hjislFijGuTcbtr+5mUz1FuweEFaH/xtHacsJ3Yth9iOiska0CbQ==;

__utmb=125759317; __utmc=125759317

HTTP/1.1 302 暂时移动日期:2011 年 9 月 23 日星期五 16:30:36 GMT

服务器:服务器 x-amz-id-1:0DVGSNJ16FJ7BZSXKZEA x-amz-id-2:

3zBVVCqaFC6uLEb69n0ImqYEWcveHC/fr3DWJZ9XwfU= 设置 Cookie:

ubid-main=190-8295480-4625243;路径=/;域名=.amazon.com;过期=星期二

格林威治标准时间 2036 年 1 月 1 日 08:00:01 地点:

https://affiliate-program.amazon.com/gp/associates/network/main .html

变化:接受编码,用户代理内容编码:gzip Cneonction:

关闭传输编码:分块内容类型: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 连接:保持活动

引荐来源:https://affiliate-program.amazon.com/ Cookie:

apn-用户-id=P0000000000; session-id-time=1317366000l;

会话 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;

at-main=4|3iPYr7E1Pn32BbMI4MHFaMtbn/0v54qEG1Jn9Pk+7Hi2Cws1f+jBSUt9oyBzrpy6BX1XCsZ/qoJlbswA0G2U3L9Yhec4CjSlsLZM+mEP Rs/AiNAbvuUDzj9wL1HI2x+e7tBqDLhK+fas6R562qkQBX+9Y7bhE1St11hjislFijGuTcbtr+5mUz1FuweEFaH/xtHacsJ3Yth9iOiska0CbQ==;

__utmb=125759317; __utmc=125759317

HTTP/1.1 200 OK 日期:2011 年 9 月 23 日星期五 16:30:36 GMT 服务器:服务器

x-amz-id-1:02WEQDKB29RGKP5T4NWE x-amz-id-2:

xFfF8ncVlxX9KZtDLganiEY4CcDu+qXwkV5CBJGrKWY= 设置 Cookie:

ubid-main=190-8295480-4625243;路径=/;域名=.amazon.com;过期=星期二

2036 年 1 月 1 日 08:00:01 GMT 变化:接受编码、用户代理

内容编码:gzip Cneonction:关闭传输编码:分块

内容类型: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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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:8080,未命中

cdn-images.amazon.com:10080 缓存控制:max-age=607570264 日期:

2011 年 9 月 23 日星期五 16:30:37 GMT 连接:保持活动状态

<小时>

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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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 日星期四 11:17:40 GMT 内容类型:image/jpeg X-Cache-Lookup:

来自 cdn-images.amazon.com 的点击: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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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 GMT 连接:保持活动状态

<小时>

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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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 GMT 内容类型:image/jpeg X-Cache-Lookup:

命中来自 cdn-images.amazon.com:8080,未命中

cdn-images.amazon.com:10080 缓存控制:max-age=607635331 日期:

2011 年 9 月 23 日星期五 16:30:37 GMT 连接:保持活动状态

<小时>

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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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 最后修改时间:

2011 年 9 月 15 日星期四 20:05:25 GMT 内容类型:image/jpeg X-Cache-Lookup:

来自 cdn-images.amazon.com 的未命中: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位&utmul=en-gb&utmje=1&utmfl=10.3%20r183&utmdt=Amaz on.com%20Associates%20Central%20-%20Home&utmhn=affiliate-program.amazon.com&utmr=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 位&utmul=en-gb&utmje=1&utmfl=10.3%20r 183&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=affiliate-program.amazon.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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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;

会话 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;

at-main=4|3iPYr7E1Pn32BbMI4MHFaMtbn/0v54qEG1Jn9Pk+7Hi2Cws1f+jBSUt9oyBzrpy6BX1XCsZ/qoJlbswA0G2U3L9Yhec4CjSlsLZM+mEP Rs/AiNAbvuUDzj9wL1HI2x+e7tBqDLhK+fas6R562qkQBX+9Y7bhE1St11hjislFijGuTcbtr+5mUz1FuweEFaH/xtHacsJ3Yth9iOiska0CbQ==;

__utmb=125759317; __utmc=125759317

HTTP/1.1 200 OK 日期:2011 年 9 月 23 日星期五 16:30:37 GMT 服务器:服务器

最后修改时间:2011 年 9 月 16 日星期五 11:22:34 GMT Etag:“23-35b3d280”

接受范围:字节内容长度:35 Cneonction:关闭

内容类型:图像/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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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 最后修改时间:

2010 年 7 月 27 日星期二 16:47:41 GMT 内容类型:image/jpeg X-Cache-Lookup:

来自 cdn-images.amazon.com 的未命中: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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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 最后修改时间:

2007 年 11 月 11 日星期日 01:27:41 GMT 内容类型:image/jpeg X-Cache-Lookup:

来自 cdn-images.amazon.com 的未命中: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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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 最后修改时间:

2010 年 7 月 27 日星期二 00:37:08 GMT 内容类型:image/jpeg X-Cache-Lookup:

来自 cdn-images.amazon.com 的未命中: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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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 最后修改时间:

2009 年 8 月 20 日星期四 15:52:47 GMT 内容类型:image/jpeg X-Cache-Lookup:

来自 cdn-images.amazon.com 的未命中:10080 缓存控制:公共,

max-age=630336792 过期时间:2031 年 9 月 14 日星期日 06:03:49 GMT 日期: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 接受语言:en-gb,en;q=0.5

接受编码:gzip、deflate 接受字符集:

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;

会话 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;

at-main=4|3iPYr7E1Pn32BbMI4MHFaMtbn/0v54qEG1Jn9Pk+7Hi2Cws1f+jBSUt9oyBzrpy6BX1XCsZ/qoJlbswA0G2U3L9Yhec4CjSlsLZM+mEP Rs/AiNAbvuUDzj9wL1HI2x+e7tBqDLhK+fas6R562qkQBX+9Y7bhE1St11hjislFijGuTcbtr+5mUz1FuweEFaH/xtHacsJ3Yth9iOiska0CbQ==;

__utmb=125759317; __utmc=125759317

HTTP/1.1 200 OK 日期:2011 年 9 月 23 日星期五 16:30:37 GMT 服务器:服务器

最后修改时间:2011 年 9 月 16 日星期五 11:22:34 GMT Etag:“23-35b3d280”

接受范围:字节内容长度:35 Cneonction:关闭

内容类型:图像/gif

<小时>

任何人都可以阐明为什么这不起作用吗?

I am trying to grab my amazon associates stats automatically via cUrl. However I am falling down at the first hurdle; logging in.

When I use the following code:

    $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);  

I get the following output:

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=/; domain=.amazon.com; expires=Thu
Sep 29 07:00:00 2011 GMT Set-cookie: session-id=181-7755537-2127814;
path=/; domain=.amazon.com; expires=Thu Sep 29 07:00:00 2011 GMT Vary:
Accept-Encoding,User-Agent Cneonction: close Transfer-Encoding:
chunked Content-Type: text/html; charset=UTF-8 Please Enable Cookies
to Continue

To continue shopping at Amazon.com, please enable cookies in your Web
browser. Learn more about cookies and how to enable them.

Once you have enabled cookies in your browser, please click on the
button below to return to the previous page.

cookie.txt contains the following:

# Netscape HTTP Cookie File

# http://curl.haxx.se/rfc/cookie_spec.html

# This file was generated by libcurl! Edit at your own risk.

.amazon.com TRUE / FALSE 1317279600 session-id-time 1317279600l

.amazon.com TRUE / FALSE 1317279600 session-id 181-7755537-2127814

Live HTTP headers:

https://affiliate-program.amazon.com/gp/flex/sign-in/select.html

POST /gp/flex/sign-in/select.html 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:

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 Connection: keep-alive

Referer: 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=(direct)|utmcsr=(direct)|utmcmd=(none);

ubid-main=190-8295480-4625243; __utmv=125759317.koicarandsup-20;

x-main=qIM@jFtaFnr4KaiFFutR7WZ1QkQHqoq9;

at-main=4|eaxYjMp+5TWMiQOn6gROkHUvCfKF3Y9hkvacYbU0+fzL3Pr1ejcGt78Tb6W5zvUYj67hWyx3AuNd3UparIBCnnrL62d5IMyn7zeFKr7GfjnPvjjaGOPArk7n7tr7go+QgBU6OZ0hKse6MJIdApDrSe2cI0Mz9XDvbumEU5twDKgq338hejMR23IXuWrvq1o0hcfN6DS0oabY7mVIddSMig==;

__utmb=125759317; __utmc=125759317 Content-Type:

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%2FJ9nAIuYZ2guks0Zz%2BPhJ07TOXuTscuc%2Fm0wgqqluPq5NShRINoiGLjiKva6ngslLoQWeKovNwYyVCyNfuwsZ7BIo6%2Fo7yaEfIK6Yb%2BZPMommN%2FI7BFrlW7wrWmaG%2FgbtSx1bg9A5DgtKBDI21j3ibebBZVN%2FP2ZrEB6upCDHEKa1pMCkP6nbOhu%2BxcrNYS%2FyS6e0bv3WiWqugclX%2FnYmBWBdNunCFtI8LKU%2FMvhDT820M%3D

HTTP/1.1 302 MovedTemporarily Date: Fri, 23 Sep 2011 16:30:35 GMT

Server: Server x-amz-id-1: 1JGFY8JCATS8GCJ05WP3 x-amz-id-2:

vNYWJ+3yN1Qrya1cxENZdlFuZNF4Yc4uYhCmoR3UFBU= Set-Cookie:

at-main=4|3iPYr7E1Pn32BbMI4MHFaMtbn/0v54qEG1Jn9Pk+7Hi2Cws1f+jBSUt9oyBzrpy6BX1XCsZ/qoJlbswA0G2U3L9Yhec4CjSlsLZM+mEPRs/AiNAbvuUDzj9wL1HI2x+e7tBqDLhK+fas6R562qkQBX+9Y7bhE1St11hjislFijGuTcbtr+5mUz1FuweEFaH/xtHacsJ3Yth9iOiska0CbQ==;

path=/; domain=.amazon.com; expires=Tue Jan 01 08:00:01 2036 GMT;

secure Set-Cookie: ubid-main=190-8295480-4625243; path=/;

domain=.amazon.com; expires=Tue Jan 01 08:00:01 2036 GMT Location:

https://affiliate-program.amazon.com/gp/associates/join/landing/main.html

Vary: Accept-Encoding,User-Agent Content-Encoding: gzip nnCoection:

close Transfer-Encoding: chunked Content-Type: text/html;

charset=UTF-8


https://affiliate-program.amazon.com/gp/associates/join/landing/main.html

GET /gp/associates/join/landing/main.html 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:

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 Connection: keep-alive

Referer: 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=(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 302 MovedTemporarily Date: Fri, 23 Sep 2011 16:30:36 GMT

Server: Server x-amz-id-1: 0DVGSNJ16FJ7BZSXKZEA x-amz-id-2:

3zBVVCqaFC6uLEb69n0ImqYEWcveHC/fr3DWJZ9XwfU= Set-Cookie:

ubid-main=190-8295480-4625243; path=/; domain=.amazon.com; expires=Tue

Jan 01 08:00:01 2036 GMT Location:

https://affiliate-program.amazon.com/gp/associates/network/main.html

Vary: Accept-Encoding,User-Agent Content-Encoding: gzip Cneonction:

close Transfer-Encoding: chunked Content-Type: text/html;

charset=UTF-8


https://affiliate-program.amazon.com/gp/associates/network/main.html

GET /gp/associates/network/main.html 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:

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 Connection: keep-alive

Referer: 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=(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:36 GMT Server: Server

x-amz-id-1: 02WEQDKB29RGKP5T4NWE x-amz-id-2:

xFfF8ncVlxX9KZtDLganiEY4CcDu+qXwkV5CBJGrKWY= Set-Cookie:

ubid-main=190-8295480-4625243; path=/; domain=.amazon.com; expires=Tue

Jan 01 08:00:01 2036 GMT Vary: Accept-Encoding,User-Agent

Content-Encoding: gzip Cneonction: close Transfer-Encoding: chunked

Content-Type: text/html; charset=UTF-8


V192206992.jpg">https://images-na.ssl-images-amazon.com/images/G/01/associates/network/thumb-slideshow-widget.V192206992.jpg

GET

/images/G/01/associates/network/thumb-slideshow-widget.V192206992.jpg

HTTP/1.1 Host: images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 4119 Last-Modified:

Wed, 02 Jun 2010 17:03:17 GMT Content-Type: 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:

Fri, 23 Sep 2011 16:30:37 GMT Connection: keep-alive


SL75.jpg">https://images-na.ssl-images-amazon.com/images/I/41WtSRWclnL.SL75.jpg

GET /images/I/41WtSRWclnL.SL75.jpg HTTP/1.1 Host:

images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 1317 Last-Modified:

Thu, 26 May 2011 11:17:40 GMT Content-Type: image/jpeg X-Cache-Lookup:

HIT from cdn-images.amazon.com:10080 Cache-Control: public,

max-age=628443948 Expires: Sat, 23 Aug 2031 08:16:25 GMT Date: Fri, 23

Sep 2011 16:30:37 GMT Connection: keep-alive


SL75.jpg">https://images-na.ssl-images-amazon.com/images/I/417XQ0XwQuL.SL75.jpg

GET /images/I/417XQ0XwQuL.SL75.jpg HTTP/1.1 Host:

images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 1321 Last-Modified:

Thu, 29 Jul 2010 04:26:28 GMT Content-Type: image/jpeg Cache-Control:

public, max-age=628496714 Expires: Sat, 23 Aug 2031 22:55:51 GMT Date:

Fri, 23 Sep 2011 16:30:37 GMT Connection: keep-alive


SL75.jpg">https://images-na.ssl-images-amazon.com/images/I/417tb3B43YL.SL75.jpg

GET /images/I/417tb3B43YL.SL75.jpg HTTP/1.1 Host:

images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 2462 Last-Modified:

Fri, 26 Jun 2009 04:52:12 GMT Content-Type: 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:

Fri, 23 Sep 2011 16:30:37 GMT Connection: keep-alive


SL75.jpg">https://images-na.ssl-images-amazon.com/images/I/41sh5uiQ83L.SL75.jpg

GET /images/I/41sh5uiQ83L.SL75.jpg HTTP/1.1 Host:

images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 1341 Last-Modified:

Thu, 15 Sep 2011 20:05:25 GMT Content-Type: image/jpeg X-Cache-Lookup:

MISS from cdn-images.amazon.com:10080 Cache-Control: public,

max-age=630611997 Expires: Wed, 17 Sep 2031 10:30:34 GMT Date: Fri, 23

Sep 2011 16:30:37 GMT Connection: keep-alive


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">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

GET

/__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

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


SL75.jpg">https://images-na.ssl-images-amazon.com/images/I/51993R08WLL.SL75.jpg

GET /images/I/51993R08WLL.SL75.jpg HTTP/1.1 Host:

images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 1325 Last-Modified:

Tue, 27 Jul 2010 16:47:41 GMT Content-Type: image/jpeg X-Cache-Lookup:

MISS from cdn-images.amazon.com:10080 Cache-Control: public,

max-age=628244375 Expires: Thu, 21 Aug 2031 00:50:12 GMT Date: Fri, 23

Sep 2011 16:30:37 GMT Connection: keep-alive


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 Host:

images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 1662 Last-Modified:

Sun, 11 Nov 2007 01:27:41 GMT Content-Type: image/jpeg X-Cache-Lookup:

MISS from cdn-images.amazon.com:10080 Cache-Control: public,

max-age=628487843 Expires: Sat, 23 Aug 2031 20:28:00 GMT Date: Fri, 23

Sep 2011 16:30:37 GMT Connection: keep-alive


SL75.jpg">https://images-na.ssl-images-amazon.com/images/I/518ISDAvx1L.SL75.jpg

GET /images/I/518ISDAvx1L.SL75.jpg HTTP/1.1 Host:

images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 1111 Last-Modified:

Tue, 27 Jul 2010 00:37:08 GMT Content-Type: image/jpeg X-Cache-Lookup:

MISS from cdn-images.amazon.com:10080 Cache-Control: public,

max-age=628003065 Expires: Mon, 18 Aug 2031 05:48:22 GMT Date: Fri, 23

Sep 2011 16:30:37 GMT Connection: keep-alive


SL75.jpg">https://images-na.ssl-images-amazon.com/images/I/4155OOdySdL.SL75.jpg

GET /images/I/4155OOdySdL.SL75.jpg HTTP/1.1 Host:

images-na.ssl-images-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

HTTP/1.1 200 OK Server: Server Content-Length: 1494 Last-Modified:

Thu, 20 Aug 2009 15:52:47 GMT Content-Type: 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


Can anyone shed some light on why this is not working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风尘浪孓 2024-12-13 05:08:00

编辑:此代码自 2016 年 6 月起已损坏。请参阅 此答案以获取解释和潜在的解决方法。上一个链接中提到的相同技术已添加到员工的登录中。


我写了这段代码,它对我来说效果很好,在最后一个 var_dump 中我看到了我所有的帐户信息和类似的东西。如果您不删除 cookie,您可以使用您的登录名向受保护的页面发出后续的curl 请求。

希望这可以帮助您了解如何做到这一点。很多时候,在大型网站上,您需要访问登录页面来设置 cookie,而且它们通常在您需要提交的表单上有 csrf 令牌。

当然,如果亚马逊稍微更改其表单或网址,则必须进行一些调整,但希望他们不要经常这样做。

<?php

$email    = '[email protected]';
$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

EDIT: This code is broken as of June 2016. See this answer for explanation and potential workaround. The same technology mentioned in the previous link was added to associates' login.


I wrote this code up and it works well for me, in the last var_dump I see all my account info and things like that. If you don't delete the cookies, you can make subsequent curl requests to protected pages with your login.

Hopefully this can help you learn about how to do it. A lot of times on big sites you need to visit the login page to get cookies set, and also they usually have csrf tokens on the forms you need to submit with them.

Of course if amazon changes their forms or url's around a bit, this will have to be adapted some, but hopefully they don't do that too often.

<?php

$email    = '[email protected]';
$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
挽袖吟 2024-12-13 05:08:00

您需要先让亚马逊设置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);  

You need to get amazon to set the cookie first.

Try:

// 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);  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文