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 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Error when retrieving file contents

    Warning: file_get_contents(http://calltrack/xxx/xxx.asp?custid=16xx79) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
    I get this error when trying to pull contents from this location, which is a customer database on our intranet. I was told by another associate that this is because it relies on the browser to authenticate my enviroment, and since its only being sent by the server it can't do this so I am rejected. I tried doing this further using curl, but I don't understand this well. Looking for someone who understands what I'm encountering and might offer some sort of insight towards a resolution. Would I need too use curl to pass the correct header/additional information (picking at straws here, I really don't understand curl processing past what I've written.)

  • #2
    New Coder
    Join Date
    Mar 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks like a server setup issue with PHP... you probably probably want to talk to the server admin.

  • #3
    New Coder
    Join Date
    Mar 2009
    Location
    Chicago, IL
    Posts
    69
    Thanks
    0
    Thanked 15 Times in 15 Posts
    It simply needs authorization, if you have username and password this script should do the trick:

    PHP Code:
    <?php
    // Initialise cURL session
    $curl curl_init();

    // Specify the username/password to use
    $user "username";
    $password "password";

    // URL to access
    $url "http://calltrack/xxx/xxx.asp?custid=16xx79";

    // Set cURL parameters for this transaction
    // Load in the destination URL
    curl_setopt($curl,CURLOPT_URL$url);
    // Place a nice friendly user-agent
    curl_setopt($curl,CURLOPT_USERAGENT,"Mozilla/4.0");
    // Return the output instead of displaying it
    curl_setopt($curl,CURLOPT_RETURNTRANSFERtrue);
    // Don't return header
    curl_setopt($curl,CURLOPT_HEADERfalse);
    // Provide credentials
    curl_setopt($curl,CURLOPT_USERPWD,$user ":" $password);
    // Follow on redirect
    curl_setopt($curl,CURLOPT_FOLLOWLOCATIONtrue);

    // execute, and log the result to curl_put.log
    $result curl_exec($curl);
    $error curl_error($curl);
    if(empty(
    $error))
    {
        echo 
    $result;
    }
    else 
    {
        
    $return "Error";
        
    $message curl_error();
    }

    // Close cURL session
    curl_close($curl);
    ?>

  • Users who have thanked steelaz for this post:

    ceylon (03-19-2009)

  • #4
    New Coder
    Join Date
    Oct 2008
    Posts
    17
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you Steelaz! This is what I was looking for, I couldn't find the proper way to pass authentication... my only other question is any familiar with a way to prompt for username/pw that could be stored, not in plaintext for use with this method. Basically I wrote a scraping program to return accounts based on fairly unrelated ID's and at this point the associate using it would have to enter their corp ID + pw to access our database... just a nudge in the right direction would be great if this is more complex then a simple c/p, I'm just not sure where to start even.


  •  

    Posting Permissions

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