cURL / Mailing Lists / curl-users / Single Mail

curl-users

trying to simulate login to UPS (willing to $pay$ for solution)

From: Vadim_ghk <vadim_at_greenhatkiteboarding.com>
Date: Sun, 30 Nov 2008 02:01:51 -0500

Hi, I've been working on a script to be able 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 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 logins in (sort of) and even displays some of my data that could 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;

?>

Thank you in advance ..

______________________________
http://www.greenhatkiteboarding.com

-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2008-11-30