php - Curl login not working -


i trying login website in php , store cookie.however not able pass login reason.here code far

first cookie , xsrf-token .you can consider $cookie_file_path exist empty

$ch               = curl_init("https://ahrefs.com/user/login");     curl_setopt($ch, curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_autoreferer, true);     curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/47.0.2526.111 safari/537.36');     curl_setopt($ch, curlopt_followlocation, 1);     curl_setopt($ch, curlopt_ssl_verifypeer, 0);     curl_setopt($ch, curlopt_ssl_verifyhost, 0);     curl_setopt($ch, curlopt_cookiejar, $cookie_file_path);     curl_setopt($ch, curlopt_cookiefile, $cookie_file_path );     curl_setopt($ch, curlopt_header, 1);     curl_setopt($ch, curlopt_referer, "");     curl_setopt($ch, curlopt_connecttimeout , 120);     curl_setopt($ch, curlopt_timeout , 0);     $result = curl_exec($ch);    

at point cookie file @ location $cookie_file_path contain ahrefs_cookie , xsrf-token

now send via post

$ch               = curl_init("https://ahrefs.com/user/login");     curl_setopt($ch, curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/47.0.2526.111 safari/537.36');     curl_setopt($ch, curlopt_httpheader, array("accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",     "accept-encoding: gzip, deflate",     "accept-language: en-us,en;q=0.8",     "content-type: application/x-www-form-urlencoded"     ));     curl_setopt($ch, curlopt_post, 1);     curl_setopt($ch, curlopt_followlocation, 1);     curl_setopt($ch, curlopt_postfields, http_build_query($curl_parameters));     curl_setopt($ch, curlopt_ssl_verifypeer, 0);     curl_setopt($ch, curlopt_ssl_verifyhost, 0);     curl_setopt($ch, curlopt_cookiejar,  $cookie_file_path  );     curl_setopt($ch, curlopt_cookiefile, $cookie_file_path );     curl_setopt($ch, curlopt_header, 1);     curl_setopt($ch, curlopt_referer, $url);     curl_setopt($ch, curlopt_connecttimeout , 120);     curl_setopt($ch, curlopt_timeout , 0);     $result = curl_exec($ch);  

here post data sending

$curl_parameters = array( "_token" => $token, # token downloading page curl , extract token value.this value refresh on each post "email" => xxxxx@gmail.com, "password" => xxxxx, "return_to" => "/", # "remember_me" => 1 ); 

here happen on successful login

post /user/login http/1.1 host: ahrefs.com:443 accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 accept-encoding: gzip, deflate accept-language: en-us,en;q=0.8 content-type: application/x-www-form-urlencoded cookie: _vwo_uuid_v2=9788fefe2a8fd2a0894175f5aa899cc9|0edcdb3cdbf14c6dbb9bd958d78f6023; ajs_anonymous_id=%224084d228-28d6-42b7-8129-3faf51983652%22; _vis_opt_s=1%7c; _vis_opt_test_cookie=1; __insp_slim=1453358056412; __insp_wid=88855823; __insp_nv=true; __insp_ref=d; __insp_targlpu=https%3a%2f%2fahrefs.com%2f; __insp_targlpt=ahrefs%20seo%20tools%3a%20backlink%20checker%20%26%20seo%20report; km_ai=jrumyefwlzb6sef5ikr900rt24e%3d; km_uq=; __insp_norec_sess=true; _vwo_uuid=9788fefe2a8fd2a0894175f5aa899cc9; _vis_opt_exp_12_combi=5; phpsessid=mf02jth4fd9nnj626p7i4lqs11; xsrf-token=eyjpdii6iit1mwxxumzpz0lpqkx3b1pobutdu2c9psisinzhbhvlijoiwgtusw1srxrbtwpky2fiaexbxc8wvzixzfnoalnwrti2wxbwdkxlbg5cl3k4vwzqvwllovjpnhpwzgzcl0xmdfvdoe1wxc8xzuplmkk1sznqbxfsbxrzzunnpt0ilcjtywmioiizzdvkmdqzodnimdawnzu0ngrkowm2y2y4ymfintkxzmfmn2qxnmy2zwe1zjkxotbioge0yjhjntvkngrknze2in0%3d; ahrefs_cookie=eyjpdii6ikzjb2nzy0u2q3d0d1wvq0tkztbun1jnpt0ilcj2ywx1zsi6ijbewdbsz1dfbvnlmlf4rtjhk1lmz1q2mfllog9suerxtgtptmfoxc9rqk1ysudiag5lvgrmzk1mog1kuwjmdwxzseq1eljbduvvmk9malhpcmcrvvcwdz09iiwibwfjijoindm0yzrlm2zhzwfmmgniyja2mddmmmi2n2e2zguymzrjoge2ogjkndfkywzhoddiywjjngrkngqwntnjy2e2zcj9; _gat=1; ajs_user_id=null; ajs_group_id=null; mp_462869d58108d4904e778d9b2b8fbead_mixpanel=%7b%22distinct_id%22%3a%20%2215262e404c33be-09e7d85a5-424f072e-384000-15262e404c48f2%22%2c%22%24initial_referrer%22%3a%20%22%24direct%22%2c%22%24initial_referring_domain%22%3a%20%22%24direct%22%7d; kvcd=1453360373661; km_vs=1; km_lv=1453360374; wootracker=rmjyzzqfbcxy; intercom-id=05c5d5fa-ccaa-4744-8c69-4fdb89bfa409; _ga=ga1.2.274586625.1453358055; _gat_eleviotracker=1; _gali=login_form origin: https://ahrefs.com referer: https://ahrefs.com/user/login upgrade-insecure-requests: 1 user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/47.0.2526.111 safari/537.36 x-devtools-emulate-network-conditions-client-id: 4e0199da-8c20-44c9-baaa-5b5ad8c56232  http/1.1 302 found cache-control: no-cache connection: keep-alive content-length: 316 content-type: text/html; charset=utf-8 date: thu, 21 jan 2016 07:13:48 gmt location: https://ahrefs.com server: nginx/1.6.2 set-cookie: remember_82e5d2c56bdd0811318f0cf078b78bfc=eyjpdii6ikthdutuxc9petjttxrnmitmwldnvm5rpt0ilcj2ywx1zsi6imxybtexshz5m2nivxbpxc8wv2lrnmhts2vkdm02vzhcuwtcl1gyb3fsb2hsvgzvctaxclwvoujzctvjvjd1qjr0ogrpyjzcsevwddlcwuvms05mofbprtr2sgnaywl6q2ncswjgrlbwbndhvtgwpsisim1hyyi6imzhmgyzzgm2zjvkowi3ndrmytyzy2q1owi5owrlowuwzwi4otu2nzqyytlmnwm3yjlkzda1m2fkyzu4otjinjeifq%3d%3d; expires=tue, 19-jan-2021 07:13:47 gmt; max-age=157679999; path=/; domain=.ahrefs.com; httponly set-cookie: xsrf-token=eyjpdii6ikxvbkvzuvlztguywge5r0zfsvwvetd3pt0ilcj2ywx1zsi6ilk3vlrfq1dvatfzs1huvfiwz2k4bxztsetrszfnvlh0qkfkqtniznbrc011akjptlvjblfvvvlgcxbncexrtthpumkytho5avpjqzhxewhrogq5rzlbpt0ilcjtywmioii5zte0zduymjdmmjywzdy5nmi4yzbinmqyotdknwrhzwniytfhyzhmzwmxmzbiztuwodeyzwjkndc4zmzimgnkin0%3d; expires=thu, 21-jan-2016 09:13:48 gmt; max-age=7200; path=/; domain=.ahrefs.com set-cookie: ahrefs_cookie=eyjpdii6ijfsu2d2wm9krjfychjkaktuazm3dhc9psisinzhbhvlijoixc9xd0i1twnvmtl4uhn5unrnumxyd014dnp6txnybnldq1hyrtdxtfvuewzym1vwwlvhbtncl0tna3nln3lvqmgzttnrovdickvhv0jqnmhielvlmepmut09iiwibwfjijoimzzkndu2owrjmmm4ntmzyjaynwzhnwfkmdgzyjc4zwywotq3m2e3mzg5yzrlnjjhyzk0zdi5yze0zjnkotiwzij9; expires=mon, 21-mar-2016 07:13:48 gmt; max-age=5184000; path=/; domain=.ahrefs.com; httponly x-powered-by: php/5.6.14-0+deb8u1 

what missing here , why can't login via post ?

edit

if set wrong username/password following

post /user/login http/1.1 host: ahrefs.com:443 accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 accept-encoding: gzip, deflate accept-language: en-us,en;q=0.8 content-type: application/x-www-form-urlencoded cookie: ajs_anonymous_id=%22e915c496-7e0b-46fc-8393-ec3c135edeac%22; _vis_opt_s=1%7c; km_ai=8tticdoosgyv7d%2f0buxmtsq%2buhc%3d; _vwo_uuid=2e9a1bbeac643740726e45feda088bb0; _vis_opt_exp_12_combi=3; phpsessid=mf02jth4fd9nnj626p7i4lqs11; remember_82e5d2c56bdd0811318f0cf078b78bfc=82e5d2c56bdd0811318f0cf078b78bfc=eyjpdii6ikthdutuxc9petjttxrnmitmwldnvm5rpt0ilcj2ywx1zsi6imxybtexshz5m2nivxbpxc8wv2lrnmhts2vkdm02vzhcuwtcl1gyb3fsb2hsvgzvctaxclwvoujzctvjvjd1qjr0ogrpyjzcsevwddlcwuvms05mofbprtr2sgnaywl6q2ncswjgrlbwbndhvtgwpsisim1hyyi6imzhmgyzzgm2zjvkowi3ndrmytyzy2q1owi5owrlowuwzwi4otu2nzqyytlmnwm3yjlkzda1m2fkyzu4otjinjeifq%3d%3d; _vwo_uuid_v2=2e9a1bbeac643740726e45feda088bb0|b8caeecf523e81382e01b6691b0f508b; _vis_opt_test_cookie=1; _gat=1; __insp_slim=1453365450618; __insp_wid=88855823; __insp_nv=true; __insp_ref=d; __insp_targlpu=https%3a%2f%2fahrefs.com%2f; __insp_targlpt=ahrefs%20seo%20tools%3a%20backlink%20checker%20%26%20seo%20report; km_lv=x; km_uq=; __insp_norec_sess=true; _gat_eleviotracker=1; xsrf-token=eyjpdii6imz3tgkrahjovmrqmkhkb3nozhdynue9psisinzhbhvlijoitthcl2hny2vgzytgntzstxpsewvxb1lvmjvveeplbfzjuzq4chrunufwwnpwvvpbstzkvfdlkzzzn3hldlpmmhdongd2cglutk91rkq2q0vjckt1zwtnpt0ilcjtywmioijjnje5nwjmotmyyzi4owe4zgfmzthiyjc1mdllyzvkmtbjmduxndg4mzq4yme5zjmyotrhnwm0ytk3zjm4ymy1in0%3d; ahrefs_cookie=eyjpdii6indoue1bz1rdow9vce1usu8wrmjwb1e9psisinzhbhvlijoiwtziatdetg1zve8zwjddnvo5bec0nmhou0vjnhfoztdptvvndvhwmetesud6zhqytjhyy1jxwgdinkfqqmz6wnlwb2hucujqsnfonmzpyjvtz0txswc9psisim1hyyi6ijzlnzy5n2vlnzy0nzy1ngu4owe5yzvlyte4mmyzyti4nmewzdqwnjbjzdbkzgm3mgrjyjrkogviogrhywm5yjyifq%3d%3d; ajs_user_id=null; ajs_group_id=null; wootracker=zra7vf7tnnp5; mp_462869d58108d4904e778d9b2b8fbead_mixpanel=%7b%22distinct_id%22%3a%20%22152630d4df88d7-087e038c3-424f072e-384000-152630d4df98b5%22%2c%22%24initial_referrer%22%3a%20%22%24direct%22%2c%22%24initial_referring_domain%22%3a%20%22%24direct%22%7d; kvcd=1453365507959; km_vs=1; _ga=ga1.2.959678603.1453360761; intercom-id=08650ca0-7181-47ec-8ecb-0a6b3c045f19; _gali=login_form origin: https://ahrefs.com referer: https://ahrefs.com/user/login?return_to=%2f upgrade-insecure-requests: 1 user-agent: mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, gecko) chrome/47.0.2526.111 safari/537.36  http/1.1 302 found cache-control: no-cache connection: keep-alive content-length: 416 content-type: text/html; charset=utf-8 date: thu, 21 jan 2016 08:39:16 gmt location: https://ahrefs.com/user/login?return_to=%2f server: nginx/1.6.2 set-cookie: xsrf-token=eyjpdii6ikrlchlis1z3ytv3rwtrzg1euklxs1e9psisinzhbhvlijoizu1madjysmp4k2vhatromhp2ekljcwnsqjrongtncfa3ek5ubmhpxc9snullvg0yvezxmgjbuhmxtlbcbw9rm3rweefguenzbzfxxc9wrfztqmlhqlbzdz09iiwibwfjijoimdrkmznkzdqwmgu5mgjkzdjmotk4mtgxmja1nwviyzzhmmfhy2qymju0njjjzme2odk1yja3oti1mmezotq3zsj9; expires=thu, 21-jan-2016 10:39:16 gmt; max-age=7200; path=/; domain=.ahrefs.com set-cookie: ahrefs_cookie=eyjpdii6imzidejguhjsumo3v2lizjhwafdwm1e9psisinzhbhvlijoim3pyykdsmduxa3vzsxrscxzob3vtbnbodndks280skj6nzj0zm94uho1zhf0rva3mvbkmthyofjawtdhtzdrajfycjrewe1rmkhpn1j6ynl2ajjcl2fbpt0ilcjtywmioiiyzmflmtdiogfknjg5ywq0ytlmmdu3ogzhmdg5odljnme5nwiyowy0ntnhn2fhzdjjyzvjntviody1mgyxmgyyin0%3d; expires=mon, 21-mar-2016 08:39:16 gmt; max-age=5184000; path=/; domain=.ahrefs.com; httponly x-powered-by: php/5.6.14-0+deb8u1 

regards


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -