Need authentication while reading file.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheMadMidget
    New Member
    • Oct 2006
    • 98

    #1

    Need authentication while reading file.

    I'm trying to use something like file_get_conten ts() but on a file that requires a username and password.

    Thanks,
    Jason
  • vssp
    Contributor
    • Jul 2006
    • 268

    #2
    H i

    Sorry i am clar can u expline breifly?

    vssp

    Comment

    • TheMadMidget
      New Member
      • Oct 2006
      • 98

      #3
      I want source from a page so I was using file_get_conten ts(), but it comes back as Unathorized Access, because it needs a username and password to access the page. Last night I found a way to do with cURL, but if there is a simpler method, that would be nice.

      [PHP]
      $url = 'http://url.goes.here.c om';
      $user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";

      $ch = curl_init();
      curl_setopt($ch , CURLOPT_USERPWD , "username:passw ord");
      curl_setopt($ch , CURLOPT_URL,$ur l);
      curl_setopt($ch , CURLOPT_SSL_VER IFYHOST, 2);
      curl_setopt($ch , CURLOPT_USERAGE NT, $user_agent);
      curl_setopt($ch , CURLOPT_RETURNT RANSFER,1);
      curl_setopt($ch , CURLOPT_FRESH_C ONNECT, TRUE);
      curl_setopt($ch , CURLOPT_MUTE, TRUE);
      curl_setopt($ch , CURLOPT_RETURNT RANSFER, TRUE);
      curl_setopt($ch , CURLOPT_SSL_VER IFYPEER, FALSE);
      $result=curl_ex ec ($ch);
      curl_close ($ch);
      [/PHP]

      Everything comes back in $result, I may have a few extra curl_setopt() but it works.

      Jason

      Comment

      Working...