$50 for php CURL script to successfully login to UPS.com

Discussion in 'PHP' started by greenhatkb, Dec 1, 2008.

  1. #1
    Hi, I've been working on a script to print UPS shipping labels directly from my shopping cart software (zen-cart). I've done some homework and tried to replicate similar Curl scripts. But there is something that UPS.com does which makes it not so easy. I think i've tried everything, but i cant even login - i get these in the header (HTTP/1.x 302 Moved Temporarily) and i try to follow through all the moved links without much success.
    The script that i have logs in (sort of) and even displays some of my data that could only be found after i login. But , when i try to do something else (like create a label) using the session cookies that were saved , it goes back and prompts me to login again. Also, even if i manually login, session cookies that go to the cookie file are different than the session cookies in the browser's login session (so it does not let me post)..
    i think i do everything to replicate the browser's behavior.. but it doesnt seem to be enough.
    Please help..
    Here's the login script (i've replaced my user id and password by {user_id} and {password} for obvious security reasons):

    
    <?php
    
     $cookie_file_path = "cookie.txt";  
     $LOGINURL = "https://www.ups.com/myups/login";
     $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch);
    
    
    
     $LOGINURL = "https://www.ups.com/one-to-one/login?ID=100&loc=en_US";
     $POSTFIELDS = "system.action=login&loc=en_US&system.screenname=DEFAULT_CONTENT&system.forwardname=LoginCustomForSSO&system.isLoggedIn=0&uid={user_id}&password={password}&returnto=%2Fmyups%2Ffinishlogin%3Fauto%3D0%26returnto%3D%2Fmyups%2Finfo%2Fhome%3Floc%3Den_US&sysid=myups&method=login&bean.id=some&bean.uid={user_id}&bean.password={password}";
        $reffer = "https://www.ups.com/myups/login";
    
     $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_POST, 1); 
        curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_REFERER, $reffer);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch); 
     
     
     $LOGINURL = "https://www.ups.com/myups/finishlogin?auto=1&returnto=/myups/info/home?loc=en_US";
     $reffer = "https://www.ups.com/myups/login";
    
     $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_REFERER, $reffer);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch); 
     
     $LOGINURL = "https://www.ups.com/myups/info/home?loc=en_US";
     $reffer = "https://www.ups.com/myups/login";
    
     $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_REFERER, $reffer);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch); 
     
     
     $LOGINURL = "https://www.ups.com/myWorkspace/home?loc=en_US";
     $reffer = "https://www.ups.com/myups/login";
    
     $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_REFERER, $reffer);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch); 
     
     
     
    
     
     print  $result; 
    
    ?>
    
    PHP:

     
    greenhatkb, Dec 1, 2008 IP
  2. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #2
    Is this a typo when you made this post?
    
    $POSTFIELDS = "system.action=login&loc=en_US&system.screenname=DEFAULT_CONTENT&system.forwardname=LoginCustomForSSO&system.isLoggedIn=0&uid={user_id}&password={password}&returnto=%2Fmyups%2Ffinishlogin%3Fauto%3D0%26returnto%3D%2Fmyups%2Finfo%2Fhome%3Floc%3Den_US&sysid=myups&method=login&bean.id=some&bean.uid={user_id}&bean.password={password}";
    
    PHP:
    You used {user_id} and {password}, maybe you forgot the $ ?

    EDIT : nevermind. I didn't see that you replaced it intentionally
     
    xrvel, Dec 4, 2008 IP
  3. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #3
    I can do this, I am curl expert , but to successfully complete the curl page I would need your user id and pass.

    PM me and I can help you. :)

    Thanks and regards
     
    harrisunderwork, Dec 4, 2008 IP
  4. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #4
    I can help you with curl, I know how curl work

    @harrisunderwork.. :)
    you can register your name by yourself... :)
     
    misbah, Dec 4, 2008 IP
  5. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #5
    I don't have any labels at UPS I can try to print to test this with, but I'm fairly sure you were killing your sessions when you closed and reopened a connection with curl_close() and curl_init() between each request.

    Try it with those reconnects commented out.

    <?php
    
     $cookie_file_path = "cookie.txt";  
     $LOGINURL = "https://www.ups.com/myups/login";
     $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
     $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
       // curl_close ($ch);
    
    
    
     $LOGINURL = "https://www.ups.com/one-to-one/login?ID=100&loc=en_US";
     $POSTFIELDS = "system.action=login&loc=en_US&system.screenname=DEFAULT_CONTENT&system.forwardname=LoginCustomForSSO&system.isLoggedIn=0&uid={user_id}&password={password}&returnto=%2Fmyups%2Ffinishlogin%3Fauto%3D0%26returnto%3D%2Fmyups%2Finfo%2Fhome%3Floc%3Den_US&sysid=myups&method=login&bean.id=some&bean.uid={user_id}&bean.password={password}";
        $reffer = "https://www.ups.com/myups/login";
    
    // $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_POST, 1); 
        curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_REFERER, $reffer);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
       // curl_close ($ch); 
     
     
     $LOGINURL = "https://www.ups.com/myups/finishlogin?auto=1&returnto=/myups/info/home?loc=en_US";
     $reffer = "https://www.ups.com/myups/login";
    
     //$ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_REFERER, $reffer);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
       // curl_close ($ch); 
     
     $LOGINURL = "https://www.ups.com/myups/info/home?loc=en_US";
     $reffer = "https://www.ups.com/myups/login";
    
    // $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_REFERER, $reffer);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
       // curl_close ($ch); 
     
     
     $LOGINURL = "https://www.ups.com/myWorkspace/home?loc=en_US";
     $reffer = "https://www.ups.com/myups/login";
    
    // $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$LOGINURL);
     curl_setopt($ch, CURLOPT_USERAGENT, $agent);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_REFERER, $reffer);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
     curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
        $result = curl_exec ($ch);
        curl_close ($ch); 
     
     
     
    
     
     print  $result; 
    
    ?>
    Code (markup):
     
    joebert, Dec 5, 2008 IP
  6. raimis100

    raimis100 Banned

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Wow , you pay 50 $ for that script :O
     
    raimis100, Dec 7, 2008 IP
  7. firman01

    firman01 Well-Known Member

    Messages:
    155
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    165
    #7
    $cookie_file_path = "cookie.txt";

    if you're having cookie problem with curl, try not using any variable on the cookies

    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

    just use like

    curl_setopt($ch, CURLOPT_COOKIEFILE, "mycookie");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "mycookie");


    btw, i saw lot of indonesian replying in this thread. so halo semua :)
     
    firman01, Dec 7, 2008 IP
  8. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #8
    PM me if you still need help. I have worked with PHP in 5 years, and is currently working as web programmer at an advertising agency. I know cURL well, and I can provide the best and fastest service for you.
     
    elias_sorensen, Dec 7, 2008 IP
  9. tenthletter

    tenthletter Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    that nice and i can work for this php coding. and also if you have any project to be done in php you can direct to me. thanks and PM me
     
    tenthletter, Dec 9, 2008 IP