I'm trying to load the stats data generated by Bing webmaster tools. I'm building urls based on desired data and trying to load that. Since file_get_contents() doesn't work with https, I've tried both a curl-based function and fopen.
Is this even possible, or does Bing somehow block this data stream from being remotely accessed? I know Google has a login process, but I have found no such thing for Bing. Instead, I've set a certificate with cURL, turned on allow_url_fopen, and enabled ssl. Var dumps and prints give me nothing except for the following messages:
when using fopen(): resource(3) of type (stream) Resource id #3
when using getBingdata(): bool(false)
Here is my function. Much of this was pieced together from tutorials on SO and elsewhere. I apologize in advance for any huge errors or omissions
function getBingData($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); //
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
// goes to Bing login page if set to false
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, true);
if(substr($url,0,4)=='http') { $temp = parse_url($url); }
else if(substr($url,0,5)=='https') { $temp = parse_url($url); }
else { $temp = parse_url('https://'.$url); }
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 0, 1, and 2 make no difference
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "./certificates/ssl.bing.com.cer");
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "./certificates/wmstat.bing.com.cer");
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
return ($info['http_code']!=200) ? false : $result;
}
I've also tried sending my bing webmaster login and password through curl, but found it made no difference. Is there something I need to do with cookies? Is there a login process for Bing? Is there a better method of getting web data from https urls? Or does everything from Bing just have to be dumped into a file for other uses?
Many thanks in advance!
ps. I'm using the output given by https://wmstat.bing.com/webmaster/data.ashx?wmkt=en-CA&wlang=en-CA&type=sitelinks&url=CLIENTURLGOESHERE&out=plain, which I know can be set to file (csv format) or saved from the browser. However, I need all or various parts of this dynamically loaded for SEO analysis and possibly dumped to a database. If I can get the contents of these generated pages directly instead of saving them to files and then reading those, it will save a lot of time and effort.