简体   繁体   中英

PHP file_get_contents() returning enable cookies?

I'm trying to do a file_get_contents() on https://satoshidice.com/api/status and it's returning this - http://puu.sh/58lCb

print file_get_contents($this->base . 'status');

$this->base is satoshidice.com/api (with the http).

Why would it return what it is in the image posted above..?

Suggest you use cURL instead of the file_get_contents

$_curl = curl_init();
curl_setopt($_curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($_curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($_curl, CURLOPT_COOKIEFILE, './cookiePath.txt');
curl_setopt($_curl, CURLOPT_COOKIEJAR, './cookiePath.txt');
curl_setopt($_curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; InfoPath.1)');
curl_setopt($_curl, CURLOPT_FOLLOWLOCATION, true); //new added
curl_setopt($_curl, CURLOPT_URL, $url);
$rtn = curl_exec( $_curl );

Updated: added the 'CURLOPT_FOLLOWLOCATION'

Explain:

For this host, it will check the cookie is exists or not.

In case the requested cookie does not exists, it will create cookie and generate the HTTP code 307 to redirect:

https://satoshidice.com/api/status?stage=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM