Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP open page function

Options
  • 04-12-2009 8:28pm
    #1
    Registered Users 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 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 Posts: 8,584 ✭✭✭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 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