Jump to content

cURL - Passing on page variable for after-login process


ian2k01

Recommended Posts

Hello everyone, I am working on a PHP cURL project for my company to automate downloading bank statement with login process. I pass through the login page no problem and able to store and reuse the cookie information;

 

but the site is a bit odd: the session/cookie i stored is in JSESSIONID, but in order for me to proceed to next page after login, there is an automatically generated SessionID which is different from JSESSIONID which i need to put on the URL request.

 

I have used network monitoring program, and was able to see the SessionID as one of the variable/parameter. But how could I do the same on PHP cURL? to get page parameter, set it as variable and reuse it to postfield? Thank you.

 

Here is my script

P.S. the SessionID would be like this: 12426624329771242662432977U[[bR??=96<692

and JSESSION would be like this: 33555EF380C964DBCDF8504A994DCBC1.78n4

<?

 

// This page will set some cookies and we will use them for Posting in Form data.

 

        $username = "aaa"; // Please set your Ebay ID

        $password = "bbb"; // Please set your Ebay Password

$clientid = "ccc";

        $cookie_file_path = "cookies/wn.txt"; // Please set your Cookie File path

 

        $LOGINURL = "https://trackpayments.westernunion.com/";

        $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);

 

// 2- Post Login Data to Page http://signin.ebay.com/aw-cgi/eBayISAPI.dll

 

        $LOGINURL = "https://trackpayments.westernunion.com/tally/Logon.do";

    $POSTFIELDS = "Errors=&LoginStatus=N&LogonID=" . $username . "&LogonAcct=" . $clientid . "&SwtAcctID=&SessionID=&IsSuperUser=&IsGroupUser=&IsAdminUser=&PageAppList=&PageFunList=&sys=&JspID=&UserID=" . $username . "&Password=" . $password . "&ClientID=" . $clientid . "&ErrorFlag=";

$reffer = "https://trackpayments.westernunion.com/";

 

        $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_COOKIEFILE, $cookie_file_path);

        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

    $result = curl_exec ($ch);

 

//extract session ID from URL

 

 

    curl_close ($ch);

       

// parse the session id into $val

 

        $dd=file('cookies/wn.txt');

 

        $expHd=explode("%09",urlencode($dd[4]));

 

        $expHd[6]=urldecode(ereg_replace("%0A","",$expHd[6]));

 

        $val=$expHd[6];

 

        header("Set-Cookie: JSESSIONID=$val; path=/");

echo $val;

 

// 3- Proceed to Quick Search

 

$LOGINURL = "https://trackpayments.westernunion.com/tally/DispatchStaticPage.do";

        $POSTFIELDS = "Errors=&LoginStatus=Y&LogonID=" . $username . "&LogonAcct=" . $clientid . "&SwtAcctID=" . $clientid . "&SessionID=" . $val . "&IsSuperUser=FALSE&IsGroupUser=FALSE&IsAdminUser=FALSE&PageAppList=%3CAPPLIST%3E%3CAPP+id%3D%22qfind%22+caption%3D%22Quick+Find%22+url%3D%22qfPaymentInquiry%22+pageType%3D%22static%22%3E%3C%2FAPP%3E%3C%2FAPPLIST%3E%0D%0A&PageFunList=%3CFUNLIST%3E%3CFN%3EF08%3C%2FFN%3E%3CFN%3EW01%3C%2FFN%3E%3CFN%3EF07%3C%2FFN%3E%3C%2FFUNLIST%3E%0D%0A&sys=&JspID=qfPaymentInquiry";

$reffer = "https://trackpayments.westernunion.com/tally/Logon.do";

 

        $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_COOKIEFILE, $cookie_file_path);

        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

    $result = curl_exec ($ch);

    curl_close ($ch);

 

// 4- Proceed to Payment by Day

 

$LOGINURL = "https://trackpayments.westernunion.com/tally/DispatchStaticPage.do";

        $POSTFIELDS = "Errors=&LoginStatus=Y&LogonID=" . $username . "&LogonAcct=" . $clientid . "&SwtAcctID=" . $clientid . "&SessionID=" . $val . "&IsSuperUser=FALSE&IsGroupUser=FALSE&IsAdminUser=FALSE&PageAppList=%3CAPPLIST%3E%3CAPP+id%3D%22qfind%22+caption%3D%22Quick+Find%22+url%3D%22qfPaymentInquiry%22+pageType%3D%22static%22%3E%3C%2FAPP%3E%3C%2FAPPLIST%3E%0D%0A&PageFunList=%3CFUNLIST%3E%3CFN%3EF08%3C%2FFN%3E%3CFN%3EW01%3C%2FFN%3E%3CFN%3EF07%3C%2FFN%3E%3C%2FFUNLIST%3E%0D%0A&sys=&JspID=qfDailyReport&GroupID=&ConsNumber=&MTCN=&Amount=&FromDate=&ToDate=&FromTime=&ToTime=&LastName=&FirstName=&Status=ALL&hdn_currentDate=5%2F21%2F2009&hdn_inputDateFormat=mm%2Fdd%2Fyyyy&Flag=A&QueryFlag=R&PageNo=1&CCID=" . $clientid . "&ReportFlag=P&Today=Thu+May+21+15%3A21%3A41+EDT+2009&ErrorFlag=";

$reffer = "https://trackpayments.westernunion.com/tally/DispatchStaticPage.do";

 

        $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_COOKIEFILE, $cookie_file_path);

        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

    $result = curl_exec ($ch);

    curl_close ($ch);

 

// 5- Scrape Daily Payment now

 

$LOGINURL = "https://trackpayments.westernunion.com/tally/DailyReport.do";

        $POSTFIELDS = "Errors=&LoginStatus=Y&LogonID=" . $username . "&LogonAcct=" . $clientid . "&SwtAcctID=" . $clientid . "&SessionID=" . $val . "&IsSuperUser=FALSE&IsGroupUser=FALSE&IsAdminUser=FALSE&PageAppList=%3CAPPLIST%3E%3CAPP+id%3D%22qfind%22+caption%3D%22Quick+Find%22+url%3D%22qfPaymentInquiry%22+pageType%3D%22static%22%3E%3C%2FAPP%3E%3C%2FAPPLIST%3E%0D%0A&PageFunList=%3CFUNLIST%3E%3CFN%3EF08%3C%2FFN%3E%3CFN%3EW01%3C%2FFN%3E%3CFN%3EF07%3C%2FFN%3E%3C%2FFUNLIST%3E%0D%0A&sys=&JspID=&GroupID=&DayOption=1&FromDate=&RepType=D&hdn_currentDate=&hdn_inputDateFormat=mm%2Fdd%2Fyyyy&ToDate=&ReportFlag=D&Period=6&PageNo=1&CCID=" . $clientid . "&ErrorFlag=";

$reffer = "https://trackpayments.westernunion.com/tally/DispatchStaticPage.do";

 

        $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_COOKIEFILE, $cookie_file_path);

        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

    $result = curl_exec ($ch);

    curl_close ($ch);

echo($result);

 

?>

 

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.