0

Is it possible to remote login, if <form has not action and method="POST" and also hidden input?

I am new in php curl, so i have many questions and i am fetching many problem.

How to i make curl request without action, method="POST" and on hidden input.

Here is full form html code:

<form class="RFjuSb bxPAYd k6Zj8d" jsname="nUpftc" jscontroller="gsfs7c" jsaction="click:v3HUwf(preventDefault=true|DPJEMd),sJqX4b(Cuz2Ue),rYhRle(preventDefault=true|RTjbJ);LfGMDc:RbvWUd;h4C2te:NGpkv;mejaPb:WWkjY;E855kc:hRLCTe;u3KAb:UHZ0U;azuPB:s57X0c;sPvj8e:XyQaue;rcuQ6b:WYd;EJh3N:.CLIENT;submit:.CLIENT;WMmLoc:.CLIENT;ms5v1:.CLIENT" data-locale="en" data-is-refreshable="" data-branding="jcJzye" role="presentation" novalidate="">

    <div jsname="uybdVe" class="mbekbe bxPAYd" role="presentation">
        <div jsname="USBQqe" class="iUe6Pd Us7fWe JhUD8d" role="presentation">
            <div class="RCum0c">


                <div jscontroller="zB5w" jsaction="keydown:C9BaXe;YqO5N:di0fJ;O22p3e:fpfTEe;AHmuwe:Jt1EX;rcuQ6b:WYd;EJh3N:WYd" jsname="dWPKW" class="fQxwff" role="presentation" data-is-rendered="true">
                    <div class="rFrNMe uIZQNc og3oZc sdJrJc Tyc9J" jscontroller="pxq3x" jsaction="clickonly:KjsqPd; focus:Jt1EX; blur:fpfTEe; input:Lg5SV;" jsshadow="" jsname="Vsb5Ub">
                        <div class="aCsJod oJeWuf">
                            <div class="aXBtI Wic03c">
                                <div class="Xb9hP"><input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="username" spellcheck="false" tabindex="0" aria-label="Email or phone" name="identifier" id="identifierId" dir="ltr" data-initial-dir="ltr" data-initial-value="">
                                    <div jsname="YRMmle" class="AxOyFc snByac" aria-hidden="true">Email or phone</div>
                                </div>
                                <div class="i9lrp mIZh1c"></div>
                                <div jsname="XmnwAc" class="OabDMe cXrdqd Y2Zypf"></div>
                            </div>
                        </div>
                        <div class="LXRPh">
                            <div jsname="ty6ygf" class="ovnfwe Is7Fhb"></div>
                            <div jsname="B34EJ" class="dEOOab RxsGPe" aria-atomic="true" aria-live="assertive"></div>
                        </div>
                    </div>
                </div>

                <input type="password" name="hiddenPassword" jsname="RHeR4d" class="yb9KU" tabindex="-1" aria-hidden="true">

            </div>
            <div jscontroller="D02xdc" jsaction="JIbuQc:UHZ0U(tJiF1e),s57X0c(LwtuAc); click:qrB6Cf(NjDI7d);NNw7lb:V2GCBc;U57Bbf:OGJhZ;PueeNd:hRLCTe;" jsname="yXBf7b" class="GtglAe" data-button-id-prefix="identifier">
                <div class="OZliR">
                    <div role="button" id="identifierNext" class="O0WRkf zZhnYe e3Duub C0oVfc Zp5qWd Hj2jlf dKVcQ" jscontroller="VXdfxd" jsaction="click:cOuCgd; mousedown:UX7yZ; mouseup:lbsD7e; mouseenter:tfO1Yc; mouseleave:JywGue;touchstart:p6p2H; touchmove:FwuNnf; touchend:yfqBxc(preventMouseEvents=true|preventDefault=true); touchcancel:JMtRjd;focus:AHmuwe; blur:O22p3e; contextmenu:mg9Pef;" jsshadow="" jsname="tJiF1e" aria-disabled="false" tabindex="0">
                        <div class="Vwe4Vb MbhUzd" jsname="ksKsZd"></div>
                        <div class="ZFr60d CeoRYc"></div>
                        <content class="CwaK9"><span class="RveJvd snByac">Next</span></content>
                    </div>
                </div>
            </div>
        </div>
    </div>

</form>

This is form line:

<form class="RFjuSb bxPAYd k6Zj8d" jsname="nUpftc" jscontroller="gsfs7c" jsaction="click:v3HUwf(preventDefault=true|DPJEMd),sJqX4b(Cuz2Ue),rYhRle(preventDefault=true|RTjbJ);LfGMDc:RbvWUd;h4C2te:NGpkv;mejaPb:WWkjY;E855kc:hRLCTe;u3KAb:UHZ0U;azuPB:s57X0c;sPvj8e:XyQaue;rcuQ6b:WYd;EJh3N:.CLIENT;submit:.CLIENT;WMmLoc:.CLIENT;ms5v1:.CLIENT" data-locale="en" data-is-refreshable="" data-branding="jcJzye" role="presentation" novalidate="">

This is first input:

<input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="username" spellcheck="false" tabindex="0" aria-label="Email or phone" name="identifier" id="identifierId" dir="ltr" data-initial-dir="ltr" data-initial-value="">

and this is hidden input:

<input type="password" name="hiddenPassword" jsname="RHeR4d" class="yb9KU" tabindex="-1" aria-hidden="true">

Again i wants to say, i am new in this programming, so please don't fell boring and don't angry with me. thanks

NB: if i don't understand you, please comment below, i will try to my best to explain again.

Edited: I found this code on stackoverflow and tried this.

<?php

$USERNAME = 'gmail';
$PASSWORD = 'gmail pass';
$COOKIEFILE = 'cookies.txt';

// initialize curl handle used for all requests
$ch = curl_init();

// set some options on the handle
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $COOKIEFILE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $COOKIEFILE);
curl_setopt($ch, CURLOPT_HEADER, 0);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);

// url of our first request fetches the account login page
curl_setopt($ch, CURLOPT_URL, 
  'https://accounts.google.com/ServiceLogin?hl=en&service=alerts&continue=http://www.google.com/alerts/manage');
$data = curl_exec($ch);

// extract form fields from account login page
$formFields = getFormFields($data);

// inject email and password into form
$formFields['Email']  = $USERNAME;
$formFields['Passwd'] = $PASSWORD;
unset($formFields['PersistentCookie']);

$post_string = http_build_query($formFields); // build urlencoded POST string for login

// set url to login page as a POST request
curl_setopt($ch, CURLOPT_URL, 'https://accounts.google.com/ServiceLoginAuth');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);

// execute login request
$result = curl_exec($ch);

// check for "Redirecting" message in title to indicate success
// based on your language - you may need to change this to match some other string
if (strpos($result, '<title>Redirecting') === false) {
    die("Login failed");
    var_dump($result);
}

// login likely succeeded - request account page; unset POST so we do a regular GET
curl_setopt($ch, CURLOPT_URL, 'https://mail.google.com/mail/h/jeu23doknfnj/?zy=e&f=1');
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, null);

// execute request for login page using our cookies
$result = curl_exec($ch);

echo $result;


// helpef functions below

// find google "#gaia_loginform" for logging in
function getFormFields($data)
{
    if (preg_match('/(<form.*?class=.?RFjuSb.*?<\/form>)/is', $data, $matches)) {
        $inputs = getInputs($matches[1]);

        return $inputs;
    } else {
        die('didn\'t find login form');
    }
}

// extract all <input fields from a form
function getInputs($form)
{
    $inputs = array();

    $elements = preg_match_all('/(<input[^>]+>)/is', $form, $matches);

    if ($elements > 0) {
        for($i = 0; $i < $elements; $i++) {
            $el = preg_replace('/\s{2,}/', ' ', $matches[1][$i]);

            if (preg_match('/name=(?:["\'])?([^"\'\s]*)/i', $el, $name)) {
                $name  = $name[1];
                $value = '';

                if (preg_match('/value=(?:["\'])?([^"\'\s]*)/i', $el, $value)) {
                    $value = $value[1];
                }

                $inputs[$name] = $value;
            }
        }
    }

    return $inputs;
}
?>

0 Answers0