php会话和重新定位

php会话和重新定位,php,curl,Php,Curl,情况: curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIESESSION, 1); curl_setopt($ch, CURLOPT_INTERFACE, $ip); curl_setopt($ch, CURLOPT_VERBOSE,

情况:

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
* About to connect() to www.thesite.org port 80 (#0)
*   Trying x.x.x.254... * Name 'x.x.29.61' family 2 resolved to 'x.x.29.61' family 2
* Local port: 0
* connected
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:05 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:05 GMT
< Set-Cookie: JSESSIONID=0A2488FF811CCDAB6A6C95C12AA3F4F8.DB4B9335DF549E1FCF56CF5BD8; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:06 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:06 GMT
< Set-Cookie: JSESSIONID=5A80785B002D8C37F73F798B75A090B4.47EF37A843F03A8253F26BC644; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

etc...
当进入站点时,它设置会话cookie并重定向到自身

问题:

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
* About to connect() to www.thesite.org port 80 (#0)
*   Trying x.x.x.254... * Name 'x.x.29.61' family 2 resolved to 'x.x.29.61' family 2
* Local port: 0
* connected
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:05 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:05 GMT
< Set-Cookie: JSESSIONID=0A2488FF811CCDAB6A6C95C12AA3F4F8.DB4B9335DF549E1FCF56CF5BD8; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:06 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:06 GMT
< Set-Cookie: JSESSIONID=5A80785B002D8C37F73F798B75A090B4.47EF37A843F03A8253F26BC644; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

etc...
将curl与
FOLLOW_RELOCATION
COOKIE_SESSION
一起使用时,它在重定向后不会应用COOKIE,并最终导致达到最大重定向限制错误

代码:

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
* About to connect() to www.thesite.org port 80 (#0)
*   Trying x.x.x.254... * Name 'x.x.29.61' family 2 resolved to 'x.x.29.61' family 2
* Local port: 0
* connected
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:05 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:05 GMT
< Set-Cookie: JSESSIONID=0A2488FF811CCDAB6A6C95C12AA3F4F8.DB4B9335DF549E1FCF56CF5BD8; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:06 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:06 GMT
< Set-Cookie: JSESSIONID=5A80785B002D8C37F73F798B75A090B4.47EF37A843F03A8253F26BC644; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

etc...
详细输出:

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
* About to connect() to www.thesite.org port 80 (#0)
*   Trying x.x.x.254... * Name 'x.x.29.61' family 2 resolved to 'x.x.29.61' family 2
* Local port: 0
* connected
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:05 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:05 GMT
< Set-Cookie: JSESSIONID=0A2488FF811CCDAB6A6C95C12AA3F4F8.DB4B9335DF549E1FCF56CF5BD8; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:06 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:06 GMT
< Set-Cookie: JSESSIONID=5A80785B002D8C37F73F798B75A090B4.47EF37A843F03A8253F26BC644; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

etc...
*即将()连接到www.thesite.org端口80(#0)
*正在尝试x.x.x.254…*名称“x.x.29.61”系列2已解析为“x.x.29.61”系列2
*本地端口:0
*连接的
*已连接到www.thesite.org(x.x.x.254)端口80(#0)
>GET/HTTP/1.1
主持人:www.thesite.org
接受:*/*
GET/HTTP/1.1
主持人:www.thesite.org
接受:*/*
GET/HTTP/1.1
主持人:www.thesite.org
接受:*/*
等
问题是:

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
* About to connect() to www.thesite.org port 80 (#0)
*   Trying x.x.x.254... * Name 'x.x.29.61' family 2 resolved to 'x.x.29.61' family 2
* Local port: 0
* connected
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:05 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:05 GMT
< Set-Cookie: JSESSIONID=0A2488FF811CCDAB6A6C95C12AA3F4F8.DB4B9335DF549E1FCF56CF5BD8; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 31 Jul 2013 15:14:06 GMT
< Server: Apache
< cache-control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< pragma: no-cache
< expires: Mon, 17 Jul 1978 05:00:00 GMT
< Last-Modified: Wed, 31 Jul 2013 15:14:06 GMT
< Set-Cookie: JSESSIONID=5A80785B002D8C37F73F798B75A090B4.47EF37A843F03A8253F26BC644; Path=/
< Location: http://www.thesite.org/
< Content-Length: 0
< Vary: Accept-Encoding
< Content-Type: text/html
< 
* Connection #0 to host www.thesite.org left intact
* Issue another request to this URL: 'http://www.thesite.org/'
* Re-using existing connection! (#0) with host www.thesite.org
* Connected to www.thesite.org (x.x.x.254) port 80 (#0)
> GET / HTTP/1.1
Host: www.thesite.org
Accept: */*

etc...

我做错了什么?如何让它工作?当然,我可以连接两次并手动设置,但这不是我想要做的,这就是为什么我使用
CURL
而不是
file\u get\u contents()

您的代码并不表示您正在使用Cookie文件在页面加载之间存储信息

添加以下几行,它应该工作得更好

$cookie_file='cookies.txt'; //Change this to wherever you want.
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);

您使用什么代码来设置curl处理程序?问题已编辑,上面的代码。是的,我不想使用文件来存储cookie。不存储任何内容就无法执行单个请求<代码>curl_setopt($ch,curl_COOKIEJAR,'/dev/null')没有帮助。