0

I'm trying to figure out why this won't work for me. I'm a complete noob when it comes to cURL, today is my first day using it. I followed a tutorial for this but obviously failed.

It should check the page and if it sees "Skill Stats" on there, then return "Success", and return "Failure" if it spots "Member Rankings".

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://services.runescape.com/m=hiscore/compare.ws?user1=Mercon185");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE); 
curl_setopt($ch, CURLOPT_POST, FALSE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);


if (stristr($output,"Skill Stats")) {
    echo 'Success';
}
if (stristr($output,"Member Rankings")) {
    echo 'Failure';
}

curl_close($ch);
?>

`

3
  • So what do you get back? Did you echo $output; to see what it returned? Did you check curl_error($ch) for errors? Jul 17, 2013 at 1:46
  • first check if $output has any data
    – DevZer0
    Jul 17, 2013 at 1:47
  • var_dump and echo $output; both return nothing. It's a blank white page.
    – user2589557
    Jul 17, 2013 at 1:50

1 Answer 1

0

You need to enable follow redirects. As I see currently, your URL redirects to http://services.runescape.com/m=hiscore/overall.ws?errorcode=1. Without follow redirects enabled, it only fetches the first page, which indeed is empty.

The final landing page though, contains the data you want, so if you add this line to your cURL options, it should work:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.