Retrieve file from url with autorization PHP

Discussion in 'PHP' started by belgin fish, Jun 5, 2010.

  1. #1
    Hi, I'm currently trying to grab a file from an external url that has an authorization box that pops up (like the default one asking for a username and password)

    How can I have a script get the contents of the page (it's a video), save it to a directory and handle the authorization (i have a username and password)

    Thanks :)
     
    belgin fish, Jun 5, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    I think what you mean is HTTP Authentication? - theirfore use cURL to login, use the following example and let me know how it goes, then use $response to proceed...

    <?php
      //the sites url...
      $url = "";
      //self explanatory...
      $http_username = "";
      $http_password = "";
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_USERPWD, $http_username . ":" . $http_password);
      curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      $response = curl_exec($curl);
      curl_close($curl);
      
      //now use $response to proceed...
    ?>
    PHP:
     
    danx10, Jun 5, 2010 IP
  3. belgin fish

    belgin fish Well-Known Member

    Messages:
    1,544
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    185
    Digital Goods:
    2
    #3
    I have a new issue, the file I'm trying to get is just posting, so how can I get the http request headers off it so i can find the main url of the video?
     
    belgin fish, Jun 5, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS
     
    gapz101, Jun 5, 2010 IP
  5. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #5
    roopajyothi, Jun 5, 2010 IP
  6. belgin fish

    belgin fish Well-Known Member

    Messages:
    1,544
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    185
    Digital Goods:
    2
    #6
    Not like posting stuff myself, but kinda simulate what the firefox live http headers does.

    edit: I could just decompile the swf on the server the explode the url out of it, anyone know how to decompile an swf? :p
     
    Last edited: Jun 6, 2010
    belgin fish, Jun 6, 2010 IP
  7. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #7
    roopajyothi, Jun 6, 2010 IP
  8. belgin fish

    belgin fish Well-Known Member

    Messages:
    1,544
    Likes Received:
    72
    Best Answers:
    0
    Trophy Points:
    185
    Digital Goods:
    2
    #8
    belgin fish, Jun 6, 2010 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    Well thats a tedious task then just simple php code....
     
    danx10, Jun 6, 2010 IP