Can't get file_get_contents working with this URL

Discussion in 'PHP' started by Yazari, Jul 30, 2007.

  1. #1
    HELLO,

    i have to run this url inside my script to ensure the moving of listners from a station to another..
    
    file_get_contents('http://user:pass@mywebsite.com:8000/admin/moveclients.xsl?mount=/radio&destination=/serveur');
    
    Code (markup):
    But it gives this error :

    Warning: file_get_contents ..... HTTP/1.1 400 Bad Request

    when tying with another URL for example file_get_contents('http://www.google.com');

    it work without any problem.. i think the probleme come from the authentification
    [url]http://user:pass@mywebsite.com[/url]
    Code (markup):
    .
     
    Yazari, Jul 30, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    The problem could also be from the port 8000 or the .xls extension. If the page truly validates a user based on the url, then file get contents should still work. In that case the .xls or the :8000 are where I'd be concerned.

    You may try using curl instead of file_get_contents. It's quite a bit more complicated but it has much more advanced functionality. Also, you may need to urlencode part of the url to get file_get_contents to work properly.
     
    jestep, Jul 30, 2007 IP
  3. Yazari

    Yazari Peon

    Messages:
    180
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello the probleme doesn't come from the port :8000 because its working like that : http://www.xxx.com:8000

    also URL encoding didn't work for me.
     
    Yazari, Jul 30, 2007 IP
  4. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #4
    I think you need to use stream_context_create function.
    Here is the code example from manual:

    
    $url = 'http://protectedstuff.com';
    $auth = base64_encode('user:password');
    $header = array("Authorization: Basic $auth");
    $opts = array( 'http' => array ('method'=>'GET',
                                               'header'=>$header));
    $ctx = stream_context_create($opts);
    echo file_get_contents($url,false,$ctx);
    
    PHP:
     
    wmtips, Jul 30, 2007 IP