Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP open page function

  • 04-12-2009 08:28PM
    #1
    Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭


    I need to call a web page to send information using PHP.

    The web page requires me to send the information over a HTTP request.
    $message = "HTTP://www.website.com/webpage.php?message=This is the message&number=14";
    

    When my information is sent properly I receive a request id as well as a status number in the form of an XML page.

    I've tried use the following code to open the webpage from my PHP.
    $xml = simplexml_load_file($address);
    $status_ = $xml->acknowledgement->status;
    $requestId = $xml->acknowledgement->requestId;
    

    However I cannot get the page to load. No error is created but the message is not stored. If I print the $address and open it in my browser it works fine.

    Anyone any idea what I could be doing wrong?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭Peter B


    Just to say when I run the file_exists() function on the address it returns false (i.e the file does not exist). It does work fine in the browser though. Any help?


  • Registered Users, Registered Users 2 Posts: 8,581 ✭✭✭TouchingVirus


    First off, http should be in lowercase when using it as part of an address.

    Secondly, try using rawurlencode($address).

    Finally, do a var_dump($xml) to see what the type & value of $xml is after you assign it to simplexml_file_load.

    The function file_exists() cannot and should not be used to check if you receive a response from a web request - it's for files on the local system only.

    Check out file_get_contents(), but remember, if the URI you're sending in $address has special characters it will need to be escaped using urlencode()


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    $message = "HTTP://www.website.com/webpage.php?message=This is the message&number=14";
    

    So you're setting up a variable called "$message", containing the URL...
    $xml = simplexml_load_file($address);
    $status_ = $xml->acknowledgement->status;
    $requestId = $xml->acknowledgement->requestId;
    

    ....but you're using a variable called "$address" to load it ?

    1) Check that the url works within a browser
    2) Try everything TouchingVirus mentioned (lowercase http://, etc)
    3) file_exists won't work, and it wouldn't work with a parameter in the URL anyway
    4) Try fixing the above $message vs $address issue


  • Registered Users, Registered Users 2 Posts: 1,086 ✭✭✭Peter B


    Both of you thanks for the help. As it turned out once I used the urlencode() function as well as the following changes it actually worked fine.
    $xml = simplexml_load_file(urlencode($address));
    $status_ = $xml->status;
    $requestId = $xml->requestId;
    

    If it wasn't for the var_dump() function I wouldn't have been able to see the contents of the $xml value.

    The $message and $address variables were just typos.

    Thanks again both of you for helping sort my problem :)


Advertisement