SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php file_get_contents can not access some url while browser can

    I'm trying to execute a url in php. Below are the urls that I run and the results

    Code PHP:
    $feedback = file_get_contents('http://google.com');
    // echo $feedback 
    // null

    Code PHP:
    $feedback = file_get_contents('http://www.bigboommedia.com:8228/');
    // echo $feeback
    // false

    Code PHP:
    $feedback = file_get_contents('http://www.bigboommedia.com:8228/MG_Exchange.asmx/SendSMSv2?');
    // I got error
    //HeadersPostResponseHTMLCookies
     
    //<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
     
    //<h4>A PHP Error was encountered</h4>
     
    //<p>Severity: Warning</p>
    //<p>Message:  file_get_contents([url]http://www.bigboommedia.com:8228/MG_Exchange.asmx/SendSMSv2[/url]) [<a href='function.file-get-contents'>function.file-//get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
    //</p>
    //<p>Filename: controllers/register.php</p>
    //<p>Line Number: 76</p>

    My last url 'http://www.bigboommedia.com:8228/MG_Exchange.asmx/SendSMSv2' however can run in the browser without error like that of using file_get_contents.
    So what could be the problem here?

  2. #2
    SitePoint Zealot Sogo7's Avatar
    Join Date
    May 2011
    Posts
    129
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The command 'file_get_contents' does just that it reads the file like a page from a book,
    a web browser by contrast interacts with the file.. javascript runs, AJAX requests are made
    & cookies are placed or read.

    So your script has to 'Talk' to the target webpage, first sending information then listening for a reply.

    Suggested reading...
    CURL (command line data transfer toolpack library) http://curl.haxx.se/
    Cookies & CURL http://www.electrictoolbox.com/php-curl-cookies/

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    67
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The url doesnt return the correct headers for php file_get_contents() to interpret. This could be due to the fact that when i go to that url it says i should provide a compaign_id.
    Code:
    Missing parameter: _campaignID.
    So in your browser you get to see that but because in reality the headers send from that url return the status code 500 file_get_contents will interpret that as "internal server error". If you use chrome you can see this if you do ctrl+shift+i and go to the tab "network" then reload the page you will see "status" 500 internal server error. In firefox and opera you can also see this.


Bookmarks

Posting Permissions

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