Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Fetch variable from another domain fsockopen or cURL ?

    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 ) 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)
    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    You cant get unparsed content from an external url so if your update.php just contains
    PHP Code:
    $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.

    PHP Code:
    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:

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

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ?!
    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
    Wood for the Trees ?

    Thanks Again
    An embarrassed
    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •