SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb provide credentials to the link using script

    Hello ,

    I have a link

    https://feed.xyz.com/cat2/latest.zip

    after clicking on this link it askes me for usename and password

    when i submit those credentials latest.zip gets downloaded.

    I want to do all this using php script.

    I wanteed to set a cron for this.
    and file should be downloaded at my sever.

    what should i do?
    curl or socekt programming ?
    any idea?

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    How does it ask for credentials? In a web page? Or in a popup?

    If it's in a popup, then you could use cURL to request the file, and send the authentication info in the cURL request:

    PHP Code:
    curl_setopt($chCURLOPT_USERPWD"username:password"); 

  3. #3
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in a popup

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Then you could use cURL:

    PHP Code:
    $url "https://feed.xyz.com/cat2/latest.zip";
    $ch curl_init();
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_USERPWD"username:password");
    $zip curl_exec($ch); 
    Now the variable $zip contains your zip file, and you can save it to disk or do something else with it.
    If it's a large file, it's probably best to save it to disk while downloading:


    PHP Code:
    $url "https://feed.xyz.com/cat2/latest.zip";
    $fp fopen("latestz.zip""w");
    $ch curl_init();
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_FILE$fp);
    curl_setopt($chCURLOPT_USERPWD"username:password");
    curl_exec($ch); 

  5. #5
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you till now for the help

    when i tried the code
    it gives me latest.zip
    but the size is 0kb
    no data in it
    where in url zip is 8.3KB

  6. #6
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    After the above code has finished, see what curl_error() returns - it should be able to help you figure out what's up.

  7. #7
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

  8. #8
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Add this option where you're setting the other options:

    PHP Code:
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse); 
    VERY IMPORTANT NOTE!
    This options makes curl assume that the SSL connection you're connecting to is trusted and doesn't check it against the CA's certificate.
    This means it will still download the file if someone else manages to hijack/ spoof the connection...

  9. #9
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's done dear..
    Thanks for the help..
    u saved my time.


Bookmarks

Posting Permissions

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