Jump to content

How to sign-in to a 3rd party web site from within a PHP script...???


angelleye

Recommended Posts

I work a lot with PayPal Web Services.  When you test applications using PayPal's test servers you must first log into your account at http://developer.paypal.com.  Only then will their test accounts work for you.

 

This can be a real pain when trying to have clients test solutions you've developed for them, or even just the fact that you have to do that everytime.  Kind of annoying.

 

Is there any way I could login to the site as a first step in my test pages so I didn't actually have to manually do it? 

 

Any information on this would be greatly appreciated.  Thanks!

Link to comment
Share on other sites

Well, actually, I use curl in my current scripts to make XML/SOAP calls to the PayPal Web Services.  I just include credentials in the SOAP requests, though, so I haven't had to dig too deep into actual curl headers.  Can you possibly refer me to a good example of this being done?  I'm having some trouble finding anything for some reason.

Link to comment
Share on other sites

Hmmm...looks like a great source but I'm not having any luck.  Following the instructions and using that FireFox tool I see that when I login it actually seems to go through a few pages.  Here's what it gave me..

 

https://developer.paypal.com/cgi-bin/devscr?__track=_logout:login/main:_login-submit

POST /cgi-bin/devscr?__track=_logout:login/main:_login-submit HTTP/1.1
Host: developer.paypal.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://developer.paypal.com/cgi-bin/devscr?cmd=_logout
Cookie: homepage=3; upct=24; KHcl0EuY7AKSMgfvHl7J5E7hPtK=bFrgcM30Gb-2b3E85K4SiHyEzsMZeRVIqxjlur44o74QGXZnvTnHGme_QggT-eQFT34cVqPLl1OhGdE_; cookie_srd_optin=true; s_pers=%20s_favsn_paypalglobal_1%3D9856380030122%7C1505841661312%3B; cookie_check=yes; login_email=andrew%40angelleye.com; INSIDE_SEARCH_PARAMS=2%3bUS%3ben_US%3bAmerica%2fLos_Angeles; navlns=0; LANG=en_US%3bUS; nMjq0zk0-yCYE_iBONIGREETTNW=; dev_login_email=andrew%40angelleye.com; wwp_ClJZM3hWN6BNtpFD0LimhmC=; __login_track=SJZDNH8fctvqVf3Kf226tZyuuqtefbzza2dCsGL5wgEnnp25shrKG7LFry0
Content-Type: application/x-www-form-urlencoded
Content-Length: 116
cmd=_login-submit&login_cmd=&login_params=&login_email=LOGIN_EMAIL&login_password=LOGIN_PW&submit=Log+In
HTTP/1.x 302 Found
Date: Wed, 09 Apr 2008 05:21:28 GMT
Server: Apache/1.3.27 (Unix) mod_ssl/2.8.12 OpenSSL/0.9.7a mod_fastcgi/2.4.2 PHP/4.3.2
Cache-Control: private
Expires: Thu, 05 Jan 1995 22:00:00 GMT
Pragma: no-cache
Set-Cookie: nMjq0zk0-yCYE_iBONIGREETTNW=Jpm8RBa7sT64hIbo8v2itdfrzX6QWIO7bstdDvYj-dzgOOwis787txlMhLTiBzIPKo7tuLE2flqqRVTd3ISWJF63NnC; expires=Sat, 06-Sep-2008 05:21:31 GMT; path=/; domain=.paypal.com
Set-Cookie: dev_login_email=andrew%40angelleye.com; expires=Mon, 06-Oct-2008 05:21:31 GMT; path=/; domain=.paypal.com
Set-Cookie: wwp_ClJZM3hWN6BNtpFD0LimhmC=; path=/; domain=.paypal.com
Set-Cookie: __login_track=SJZDNH8fctvqVf3Kf226tZyuuqtefbzza2dCsGL5wgEnnp25shrKG7LFry0; path=/; domain=.paypal.com
Location: https://developer.paypal.com/cgi-bin/devscr?cmd=_login-processing&login_cmd=_login-done&login_access=0
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1
----------------------------------------------------------
https://developer.paypal.com/cgi-bin/devscr?cmd=_login-processing&login_cmd=_login-done&login_access=0

GET /cgi-bin/devscr?cmd=_login-processing&login_cmd=_login-done&login_access=0 HTTP/1.1
Host: developer.paypal.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://developer.paypal.com/cgi-bin/devscr?cmd=_logout
Cookie: homepage=3; upct=24; KHcl0EuY7AKSMgfvHl7J5E7hPtK=bFrgcM30Gb-2b3E85K4SiHyEzsMZeRVIqxjlur44o74QGXZnvTnHGme_QggT-eQFT34cVqPLl1OhGdE_; cookie_srd_optin=true; s_pers=%20s_favsn_paypalglobal_1%3D9856380030122%7C1505841661312%3B; cookie_check=yes; login_email=LOGIN_EMAIL; INSIDE_SEARCH_PARAMS=2%3bUS%3ben_US%3bAmerica%2fLos_Angeles; navlns=0; LANG=en_US%3bUS; nMjq0zk0-yCYE_iBONIGREETTNW=Jpm8RBa7sT64hIbo8v2itdfrzX6QWIO7bstdDvYj-dzgOOwis787txlMhLTiBzIPKo7tuLE2flqqRVTd3ISWJF63NnC; dev_login_email=LOGIN_EMAIL; wwp_ClJZM3hWN6BNtpFD0LimhmC=; __login_track=SJZDNH8fctvqVf3Kf226tZyuuqtefbzza2dCsGL5wgEnnp25shrKG7LFry0

HTTP/1.x 200 OK
Date: Wed, 09 Apr 2008 05:21:31 GMT
Server: Apache/1.3.27 (Unix) mod_ssl/2.8.12 OpenSSL/0.9.7a mod_fastcgi/2.4.2 PHP/4.3.2
Cache-Control: private
Expires: Thu, 05 Jan 1995 22:00:00 GMT
Pragma: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
----------------------------------------------------------
https://developer.paypal.com/cgi-bin/devscr?cmd=_login-done&login_access=0

GET /cgi-bin/devscr?cmd=_login-done&login_access=0 HTTP/1.1
Host: developer.paypal.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: https://developer.paypal.com/cgi-bin/devscr?cmd=_login-processing&login_cmd=_login-done&login_access=0
Cookie: homepage=3; upct=24; KHcl0EuY7AKSMgfvHl7J5E7hPtK=bFrgcM30Gb-2b3E85K4SiHyEzsMZeRVIqxjlur44o74QGXZnvTnHGme_QggT-eQFT34cVqPLl1OhGdE_; cookie_srd_optin=true; s_pers=%20s_favsn_paypalglobal_1%3D9856380030122%7C1505841661312%3B; cookie_check=yes; login_email=LOGIN_EMAIL; INSIDE_SEARCH_PARAMS=2%3bUS%3ben_US%3bAmerica%2fLos_Angeles; navlns=0; LANG=en_US%3bUS; nMjq0zk0-yCYE_iBONIGREETTNW=Jpm8RBa7sT64hIbo8v2itdfrzX6QWIO7bstdDvYj-dzgOOwis787txlMhLTiBzIPKo7tuLE2flqqRVTd3ISWJF63NnC; dev_login_email=LOGIN_EMAIL; wwp_ClJZM3hWN6BNtpFD0LimhmC=; __login_track=SJZDNH8fctvqVf3Kf226tZyuuqtefbzza2dCsGL5wgEnnp25shrKG7LFry0

HTTP/1.x 200 OK
Date: Wed, 09 Apr 2008 05:21:33 GMT
Server: Apache/1.3.27 (Unix) mod_ssl/2.8.12 OpenSSL/0.9.7a mod_fastcgi/2.4.2 PHP/4.3.2
Cache-Control: must-revalidate, proxy-revalidate, no-cache
Set-Cookie: nMjq0zk0-yCYE_iBONIGREETTNW=8qM5LB9CpXGBE5a_I5Rhcbxm4Gh5sb9jkHZIp48LnFbNJ_aBcwM3cLz6hMWmXxvggy0dck9TI_dy2xGNAa9b_KE9Nme; expires=Sat, 06-Sep-2008 05:21:34 GMT; path=/; domain=.paypal.com
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
----------------------------------------------------------

 

So based off that and trying to go off this sample I've got the following:

 

<?php
include_once("../includes/Functions.php");

$PayPalDevUsername = "LOGIN_EMAIL";
$PayPalDevPassword = "LOGIN_PASSWORD";

$PayPalDevLoginURL = "https://developer.paypal.com/cgi-bin/devscr?__track=_home:login/main:_login-submit";
$PayPalDevLoginCredentials = "cmd=_login-submit&login_cmd=&login_params=&login_email=" . $PayPalDevUsername . "&login_password=" . $PayPalDevPassword . "&submit=Log+In";
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_URL, $PayPalDevLoginURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_REFERER, "https://developer.paypal.com/devscr?cmd=_logout");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $PayPalDevLoginCredentials);
$res = curl_exec($ch);
curl_close($ch);


$PayPalDevLoginURL = "https://developer.paypal.com/cgi-bin/devscr?cmd=_login-processing&login_cmd=_login-done&login_access=0";
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_URL, $PayPalDevLoginURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_REFERER, "https://developer.paypal.com/devscr?cmd=_logout");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$res = curl_exec($ch);
curl_close($ch);

$PayPalDevLoginURL = "https://developer.paypal.com/cgi-bin/devscr?cmd=_login-done&login_access=0";
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_URL, $PayPalDevLoginURL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_REFERER, "Referer: https://developer.paypal.com/cgi-bin/devscr?cmd=_login-processing&login_cmd=_login-done&login_access=0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$res = curl_exec($ch);
curl_close($ch);
?>

 

When I run that I get a blank white page and I still can't access the PayPal sandbox.  Any ideas??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.