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 2 of 2
  1. #1
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts

    SOLVED: authenticate proxy server with file_get_contents()

    Hey there guys,
    I'm trying to figure out how to use file_get_contents with a user/pass authenticated proxy server....

    I've tried the following two implentations from snippets l've found online in various places, but neither seem to work.

    Can anyone see what l'm doing wrong?


    PHP Code:
    $auth base64_encode('xxx:xxx');
    $url 'http://ipchicken.com';

    $opts = array(
        
    'http' => array (
            
    'method'=>'GET',
            
    'header'=>"Authorization: Basic $auth"
            
    'proxy'=> 'tcp://69.162.140.112:62266'
        
    )
    );
    $ctx stream_context_create($opts);

    file_get_contents($urlfalse$ctx); 
    PHP Code:
    $aContext = array(
                    
    'http' => array(
                                    
    'proxy' => "tcp://69.162.140.112:62266"
                                    
    'request_fulluri' => True,
                                    
    'userid'=>"xxx",
                                    
    'password'=>"xxx"

                                    
    ),
                    );
       
    $context stream_context_create($aContext);

    echo 
    file_get_contents("http://www.ipchicken.com"0$context); 
    PS> my user/pass is correct l've triple checked.
    Last edited by Coastal Web; 01-05-2012 at 02:31 AM. Reason: solved problem

  • #2
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Got it with:

    PHP Code:
    <?php


    $auth 
    base64_encode('username:password');
    $url 'http://ipchicken.com';


    $opts = array(
        
    'http' => array (
            
    'method'=>'GET',
            
    'proxy'=>'tcp://69.162.120.112:62266',
            
    'request_fulluri' => true,
            
    'header'=> array("Proxy-Authorization: Basic $auth""Authorization: Basic $auth")

        ),
        
    'https' => array (
            
    'method'=>'GET',
            
    'proxy'=>'tcp://69.162.120.112:62266',
            
    'request_fulluri' => true,
            
    'header'=> array("Proxy-Authorization: Basic $auth""Authorization: Basic $auth")
        )
    );
    $ctx stream_context_create($opts);
    $content file_get_contents($url,false,$ctx);

    echo 
    $content;

    ?>
    Trick is to use both Proxy-Authorization and Authorization in the header.


  •  

    Posting Permissions

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