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
Share on other sites

Try this:

<?php
$URL = "http://hiscore.runescape.com/index_lite.ws?player=" . $_GET['player'];
$ch = curl_init($URL);

curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

curl_exec($ch);
curl_close($ch);
?>  

Link to comment
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.