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:
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
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
I can help you with curl, I know how curl work @harrisunderwork.. you can register your name by yourself...
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):
$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
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.
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