Using cURL to load an HTML source site, but getting a different file than intended

I am trying to use cURL and PHP to load an HTML source (as shown in the browser) here . But instead of the actual source code, it returns instead (the meta update link is set to 0).

<html> <head><title>Object moved</title></head> <body> <h2>Object moved to <a href="https://login.live.com/login.srf?wa=wsignin1.0&amp;rpsnv=11&amp;checkda=1&amp;ct=1321044850&amp;rver=6.1.6195.0&amp;wp=MBI&amp;wreply=http:%2F%2Fwww.windowsphone.com%2Fen-US%2Fapps%2Fea39f002-ac30-e011-854c-00237de2db9e&amp;lc=1033&amp;id=268289">here</a>. </h2> </body> </html> 

I'm trying to fake a referral title to be a site, but it seems like I'm doing it wrong. The code is below. Any suggestions? Thanks

 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.windowsphone.com/en-US/apps/ea39f002-ac30-e011-854c-00237de2db9e'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.6 (KHTML, like Gecko) Chrome/16.0.897.0 Safari/535.6'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ch, CURLOPT_AUTOREFERER, false); curl_setopt($ch, CURLOPT_REFERER, "http://www.windowsphone.com/en-US/apps/ea39f002-ac30-e011-854c-00237de2db9e"); $html = curl_exec($ch); curl_close($ch); 
+4
source share
3 answers
 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.windowsphone.com/en-US/apps/ea39f002-ac30-e011-854c-00237de2db9e'); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.6 (KHTML, like Gecko) Chrome/16.0.897.0 Safari/535.6'); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_REFERER, "http://www.windowsphone.com"); $html = curl_exec($ch); curl_close($ch); echo $html; 
+2
source

Add a curl parameter to follow the redirect:

 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 

If it's a meta update and not a header moved by HTTP, see PHP: Can CURL follow meta redirects

As already mentioned, flesk, you may also need to store cookies.

+6
source

The problem is not the referrer, but the fact that you need to enable cookies for it to work.

Try something like this:

 curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); 

You need to request the page twice. First enable redirects to receive a cookie from login.live.com, then request again using a set of cookies.

+1
source

Source: https://habr.com/ru/post/1380844/


All Articles