PHP可能存在cookie问题?

PHP可能存在cookie问题?,php,javascript,session,cookies,curl,Php,Javascript,Session,Cookies,Curl,我正在制作一个网络爬虫,它可以从一个网站上提取数据,而且几乎是在家里,但是我遇到了一个问题。我可以很好地登录/检索cookie,但以这种方式登录时,网站的反应异常。(请参阅屏幕截图) 看起来,一旦页面最初加载,cookie就变得毫无用处了(我已经检查过了,cookie仍然存在)。有人知道我做错了什么吗?我试着四处看看类似的问题,但没有结果 代码: 注意:如果我定期在另一个后台窗口登录,该页面的效果会稍微好一些。还有更多信息需要加载。这让我很困惑,因为cookie不是由服务器上的PHP脚本处理

我正在制作一个网络爬虫,它可以从一个网站上提取数据,而且几乎是在家里,但是我遇到了一个问题。我可以很好地登录/检索cookie,但以这种方式登录时,网站的反应异常。(请参阅屏幕截图)

看起来,一旦页面最初加载,cookie就变得毫无用处了(我已经检查过了,cookie仍然存在)。有人知道我做错了什么吗?我试着四处看看类似的问题,但没有结果

代码:


注意:如果我定期在另一个后台窗口登录,该页面的效果会稍微好一些。还有更多信息需要加载。这让我很困惑,因为cookie不是由服务器上的PHP脚本处理的吗?欧欧欧

---更新--- 好吧,我不知道为什么,因为我没有改变任何东西,但现在当我加载网站时,它看起来很正常,只是没有我想要的信息()。但是,它显示我已注销。(注意:您无法在注销时查看配置文件,它会强制您进入登录屏幕)

以下是请求回显和var_转储的打印输出:

据我所知,即使我得到了cookie,该网站仍然认为我已注销


提前谢谢

当您跳转到网站的其他部分时,需要指定cookie并执行类似操作

function login(){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//add this line
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//add this line
   curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;  rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
   curl_setopt ($ch, CURLOPT_COOKIEJAR, getcwd().'/cookie.txt');
   curl_setopt ($ch, CURLOPT_COOKIEFILE, getcwd().'/cookie.txt');
   curl_setopt($ch, CURLINFO_HEADER_OUT, true);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt ($ch, CURLOPT_REFERER, "http://www.callofduty.com/"); 
   curl_setopt($ch, CURLOPT_URL,"https://profile.callofduty.com/elite/login");
   curl_exec($ch);

   curl_setopt ($ch, CURLOPT_REFERER, "https://profile.callofduty.com/elite/login"); 
   curl_setopt($ch, CURLOPT_URL, 'https://profile.callofduty.com/elite/do_login');
   curl_setopt ($ch, CURLOPT_POST, 1);
   curl_setopt ($ch, CURLOPT_POSTFIELDS, 'j_username=USERNAME&j_password=PASSWORD');
   echo "Initial Dump: <p>";
   echo curl_exec($ch);
}

function getPlayer(){
   login();

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch,  CURLOPT_URL,"https://elite.callofduty.com/career/xbox/54d10030cc86b1b9c3162b395d46bffe#/playercardmw3");
   curl_setopt ($ch, CURLOPT_COOKIEFILE, "cookies.txt");//add this line
   curl_exec($ch);
   echo "<hr/>Second Dump: <p>";
   var_dump(curl_getinfo($ch));
}
函数登录(){
$ch=curl_init();
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);//添加此行
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);//添加此行
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0(Windows;U;Windows NT 5.1;en-US;rv:1.8.1.13)Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch,CURLOPT_COOKIEJAR,getcwd()。/cookie.txt');
curl_setopt($ch,CURLOPT_COOKIEFILE,getcwd()。/cookie.txt');
curl_setopt($ch,CURLINFO_HEADER_OUT,true);
curl_setopt($ch,CURLOPT_头,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_REFERER,”http://www.callofduty.com/"); 
curl_setopt($ch,CURLOPT_URL,”https://profile.callofduty.com/elite/login");
curl_exec($ch);
curl_setopt($ch,CURLOPT_REFERER,”https://profile.callofduty.com/elite/login"); 
curl_setopt($ch,CURLOPT_URL,'https://profile.callofduty.com/elite/do_login');
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'j_username=username&j_password=password');
回显“初始转储:”;
echo curl_exec($ch);
}
函数getPlayer(){
登录();
$ch=curl_init();
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_URL,”https://elite.callofduty.com/career/xbox/54d10030cc86b1b9c3162b395d46bffe#/playercardmw3");
curl_setopt($ch,CURLOPT_COOKIEFILE,“cookies.txt”);//添加此行
curl_exec($ch);
echo“
第二次转储:”; 变量转储(curl_getinfo($ch)); }

我没有测试这个,因为你的代码乱七八糟,但是试试看。

窃取他人IP的方法。没有IP被盗。我刚刚搜索了“Joe”作为测试配置文件,这是出现的第一件事:Pi应该澄清,在这种情况下,IP是知识产权。我不打算出售它或任何东西。我只是想知道这些东西是怎么工作的。我通过修改已经在工作的东西学习的最好。好的,请参考我的更新部分。现在完全变了
function login(){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//add this line
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//add this line
   curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;  rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
   curl_setopt ($ch, CURLOPT_COOKIEJAR, getcwd().'/cookie.txt');
   curl_setopt ($ch, CURLOPT_COOKIEFILE, getcwd().'/cookie.txt');
   curl_setopt($ch, CURLINFO_HEADER_OUT, true);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt ($ch, CURLOPT_REFERER, "http://www.callofduty.com/"); 
   curl_setopt($ch, CURLOPT_URL,"https://profile.callofduty.com/elite/login");
   curl_exec($ch);

   curl_setopt ($ch, CURLOPT_REFERER, "https://profile.callofduty.com/elite/login"); 
   curl_setopt($ch, CURLOPT_URL, 'https://profile.callofduty.com/elite/do_login');
   curl_setopt ($ch, CURLOPT_POST, 1);
   curl_setopt ($ch, CURLOPT_POSTFIELDS, 'j_username=USERNAME&j_password=PASSWORD');
   echo "Initial Dump: <p>";
   echo curl_exec($ch);
}

function getPlayer(){
   login();

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch,  CURLOPT_URL,"https://elite.callofduty.com/career/xbox/54d10030cc86b1b9c3162b395d46bffe#/playercardmw3");
   curl_setopt ($ch, CURLOPT_COOKIEFILE, "cookies.txt");//add this line
   curl_exec($ch);
   echo "<hr/>Second Dump: <p>";
   var_dump(curl_getinfo($ch));
}