View Full Version : Fetch variable from another domain fsockopen or cURL ?

10-26-2006, 12:49 PM
I have a script that needs to check the 'mother site' for version information. The site contains an updates.php page that simply contains one variable
$current = 1;
I initially tried to simple add this page as an include but found it would not work.
I have been having a look around and it seems that I have two options. fsockopen or cURL.
I know nothing about cURL and have never used fsockopen (we are off to a good start aren't we :rolleyes: ) So before I take a hike up the learning curve I just thought I would get some advice on what would be the best option. The server the update.php page is on has cURL enabled. A phpinfo() gives me

libcurl/7.10.3 OpenSSL/0.9.6g ipv6 zlib/1.2.1

But I cannot (whether or not it matters) guarantee the servers the script that requires update.php will have it enabled.

What do you think ?

(the ever awaiting wisdom)

10-26-2006, 01:06 PM
You cant get unparsed content from an external url so if your update.php just contains

$current = 1;

and you're trying to get the variable $current in your page then it wont work, your updates.php needs to output something eg.

echo $current;

then you can do a number of things to get that value - if you cant guarentee curl will available and you want something as simple as a version number then you can simply do:

$current = file_get_contents("http://www.domain.com/update.php");

10-26-2006, 01:34 PM
Thanks Nancy that works just fine.

Do you know I was mucking around with file_get_contents() earlier to see if I could use that. But Dismissed it as it only fetched text... at this point I am groaning with my head in my hands. Why didn't I just think to turn what it fetches into a variable ?! :rolleyes:
Big Tick in the Doh! box for me and a big tick in the Thank you box for you :)

Don't laugh but I have just spent the past three hours trying to track down a solution for that :o
Wood for the Trees ?

Thanks Again
An embarrassed