Jump to content

New to cURL and it won't work!


mtoldfield

Recommended Posts

Hello.

 

I am trying to make a statistic signature for a game called RuneScape, in which will take the users statistics from the game's hiscore page. Recently, a new version for webmasters has been released, in which is just a very very basic output for people to parse and do what they like with it.

 

I had trouble trying to connect to the page, as it's not something I've had the need to do before, and I was suggested by someone to use either sockets or cURL. Sockets really confused me, and cURL appears to be exactly what I'm looking for, but how it works is a mystery to me.

 

This is the code I have, after reading some function lists, cURL guides, etc:

 

<?php

ob_start();

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://hiscore.runescape.com/index_lite.ws?player=" . $_GET['name']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$output = curl_exec($ch);
print $output; // Test it works before actually doing anything else...

curl_close($ch);

ob_end_flush();

?>

 

Nothing happens. I've tried getting it to just print it straight off without me telling it to do anything else (So basically not putting it in a variable, and not having the RETURNTRANSFER that I read I should have), and nothing happens. The $_GET['name'] value is "lostwallaby", so it is supposed to be retrieving http://hiscore.runescape.com/index_lite.ws?player=lostwallaby, which when visiting in my browser, works fine.

 

I've tried many different things, and nothing works. I thought it might be no cURL library on my server, so I tried another server, and it doesn't like curl_init(), as it is an unidentified function, so I therefore ruled out this conclusion.

 

Does anyone have any ideas?

Link to comment
https://forums.phpfreaks.com/topic/63012-new-to-curl-and-it-wont-work/
Share on other sites

Thank you, however, it still only displays a blank page when I try that.

 

It appears that after I have declared...

 

$ch = curl_init($url);

 

...Nothing is printable. I placed a line, print 'Test';, on every line between every line of code, and nothing printed, unless it was before $ch.

Or you can use the snoopy library, it is a collection of pre-written cURL functions that are so simple to call up, it almost seems like cheating.  Look it up on google, "php snoopy library", I use it and it's great, saves the text of the page that you can call up by url, this is the syntax:

 

<?php
include('snoopy.php');
$snoopy = new Snoopy;
$snoopy->fetch("URL");
$text = $snoopy->results();
?>

 

$text would contain the returned source code from URL, it's really nice.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.