Mix1988 Posted February 7, 2013 Share Posted February 7, 2013 Hello, i have managed to use cURL many times with different sites, but now i have problem, i think it is cookie related. Site wants session id to display data, my code is as follows: $url3 = "https://vs.lkf.ee/pls/xlk/!sysadm.ic_vehicle_history_pkt.show_form"; $html3 = new simple_html_dom(); $data2 = array('p_vin' => 'WBADF81050BT08604', 'p_request' => ' Otsi ' ); $ch3 = curl_init(); curl_setopt($ch3, CURLOPT_URL,$url3); curl_setopt($ch3, CURLOPT_FAILonerror, 1); curl_setopt($ch3, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch3, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch3, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch3, CURLOPT_SSLVERSION, 3); curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch3, CURLOPT_POST, 1); curl_setopt($ch3, CURLOPT_POSTFIELDS, $data2); curl_setopt($ch3, CURLOPT_COOKIESESSION, true); curl_setopt($ch3, CURLOPT_COOKIEJAR, "/cookies.txt"); curl_setopt($ch3, CURLOPT_COOKIEFILE, "/cookies.txt"); $result4 = curl_exec($ch3); if ($result4 === FALSE) { echo ("ERROR: " . curl_error($ch3)); } print_r($result4); So, it prints me site header, some links and then "Session broken (SESSION_ERROR_NULL_KEY)" I think this can be resolved with cookies, but it is not saving any cookies to cookies.txt, i have write permissions on file and everything, but no luck. Maybe problem is elswhere, any help will be appreaciated! Site html is here: http://pastebin.com/PiEGGAUp it has lot of javascript in it that does not make any sense for me . Quote Link to comment https://forums.phpfreaks.com/topic/274167-curl-cookie-problem/ Share on other sites More sharing options...
Kingy Posted February 7, 2013 Share Posted February 7, 2013 I may be wrong but I think you need to pass through all input values for it to work. There are a couple of hidden inputs that I can see in the code. I usually use Developer Tools in Chrome to debug exactly what post variables/cookies are used and go from there. Quote Link to comment https://forums.phpfreaks.com/topic/274167-curl-cookie-problem/#findComment-1410854 Share on other sites More sharing options...
Mix1988 Posted February 7, 2013 Author Share Posted February 7, 2013 I may be wrong but I think you need to pass through all input values for it to work. There are a couple of hidden inputs that I can see in the code. I usually use Developer Tools in Chrome to debug exactly what post variables/cookies are used and go from there. Thanks, i forgot about hidden field, ok now i got a bit further. Now it displays me captcha, thing is, when i got to this site with my browser there is no captcha nessecery to submit the form, so i guess it still has something to do with cookies. By the way cURL is still not saving any cookies from site. Quote Link to comment https://forums.phpfreaks.com/topic/274167-curl-cookie-problem/#findComment-1410859 Share on other sites More sharing options...
Christian F. Posted February 7, 2013 Share Posted February 7, 2013 That's because you've told it to create the cookie file on the root filesystem, a location you don't have write access to. Either remove the slash (/) from the cookie name, or select another folder which you can write to. Quote Link to comment https://forums.phpfreaks.com/topic/274167-curl-cookie-problem/#findComment-1410868 Share on other sites More sharing options...
Mix1988 Posted February 11, 2013 Author Share Posted February 11, 2013 That's because you've told it to create the cookie file on the root filesystem, a location you don't have write access to. Either remove the slash (/) from the cookie name, or select another folder which you can write to. It doesnt work even without slash. <?php $url3 = "https://vs.lkf.ee/pls/xlk/!sysadm.ic_vehicle_history_pkt.show_form"; $data2 = array('p_vin' => 'WBADF81050BT08604','p_key' => 'c0kveql7gz8cr18w2pn23dtzyv33zth6', 'p_request' => ' Otsi ' ); $ch3 = curl_init(); curl_setopt($ch3, CURLOPT_URL,$url3); curl_setopt($ch3, CURLOPT_FAILonerror, 1); curl_setopt($ch3, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch3, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); curl_setopt($ch3, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch3, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch3, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch3, CURLOPT_SSLVERSION, 3); curl_setopt($ch3, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch3, CURLOPT_POST, 1); curl_setopt($ch3, CURLOPT_POSTFIELDS, $data2); curl_setopt($ch3, CURLOPT_COOKIESESSION, true); curl_setopt($ch3, CURLOPT_COOKIEJAR, "cookies.txt"); curl_setopt($ch3, CURLOPT_COOKIEFILE, "cookies.txt"); $result4 = curl_exec($ch3); if ($result4 === FALSE) { echo ("ERROR: " . curl_error($ch3)); } print_r($result4); ?> I figured out, that this "p_key" thingie is most important for getting results from page. If i leave p_key empty, it tells me session id NULL, How is this p_key generated? And how could i immitate it with curl ? I still think it is related with cookies somehow? Site html is as follows <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" NAME="p_name" CONTENT="text/html; charset=windows-1257"> <TITLE>Sõiduki liikluskahjude kontroll</TITLE> <LINK REL="StyleSheet" HREF="[url="https://vs.lkf.ee/pls/xlk/WEBVIEW.IES_STYLESHEET.style?pstyle=LKF20030522"]WEBVIEW.IES_STYLESHEET.style?pstyle=LKF20030522[/url]" TYPE="text/css"> </HEAD> <div id="header-div"> <A HREF="[url="http://www.lkf.ee/"]http://www.lkf.ee[/url]"><IMG SRC="[url="https://vs.lkf.ee/images/eksl_logo_rgb_v.png"]/images/eksl_logo_rgb_v.png[/url]" ALT="LKF" id="header-logo-eksl", border="0"></A> </div> <div style="margin-left:20px;margin-top:15px;margin-bottom:15px;"> <TABLE > <TR> <TD width= "422.5" style="min-width:422.5;max-width:422.5;"><font id="header-text">Sõiduki liikluskahjude kontroll</font></TD> <TD ALIGN="right" width= "422.5" style="min-width:422.5;max-width:422.5;"><A HREF="[url="http://www.lkf.ee/"]http://www.lkf.ee[/url]" style="color:#1459C0;font-size:11px;text-decoration:none">Avaleht</A> <span style="background-color:#D7D847;"> </span> <A HREF="[url="http://www.lkf.ee/index.php?option=com_content&view=article&id=294&Itemid=210&lang=et"]http://www.lkf.ee/index.php?option=com_content&view=article&id=294&Itemid=210&lang=et[/url]" style="color:#1459C0;font-size:11px;text-decoration:none">Avalikud päringud</A> <span style="background-color:#D7D847;"> </span> <A HREF="[url="https://vs.lkf.ee/pls/xlk/!sysadm.ic_vehicle_history_pkt.show_form"]!sysadm.ic_vehicle_history_pkt.show_form[/url]" style="color:#1459C0;font-size:11px;text-decoration:none">Sõiduki liikluskahjude kontroll</A></TD> </TR> </TABLE> </div> <div id="body-div"> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-36263773-1']); _gaq.push(['_setDomainName', 'lkf.ee']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <TABLE cellpadding="6px" cellspacing="0px" border="0px" style="table-layout:fixed;"> <TR class="resultHeaderRow"> <TH width="870" valign="middle" align="left" style="padding-left:20px;min-width:845px;max-width:845px;">Päringu sisend</TH> </TR> </TABLE> <FORM ACTION="!sysadm.ic_vehicle_history_pkt.show_form" METHOD="POST" name="p_frm" id="p_frm"> <INPUT TYPE="hidden" NAME="aacxooqa7niv" VALUE="359933"><script>document.p_frm.aacxooqa7niv.value = 273553 + 137394;</script> <INPUT TYPE="hidden" NAME="p_key" VALUE="3vgqv75602eh8kusfl8yvaks9jrj9gne"> <INPUT TYPE="hidden" NAME="poulibijh5vfle6zlf32c" VALUE="415024"><script>document.p_frm.poulibijh5vfle6zlf32c.value = 954316 + parseInt(document.p_frm.aacxooqa7niv.value);</script> <TABLE cellpadding="0px" cellspacing="0px" style="table-layout:fixed";> <TR> <TD width="20" style="min-width:20px;max-width:20px;"></TD> <TD width="250" style="min-width:250px;max-width:250px;"></TD> <TD width="600" style="min-width:600px;max-width:600px;"></TD> </TR> <TR> <TD valign="top", style="padding-left:3px;padding-top:6px;padding-bottom:3px;"><script>var sgfnqpy1ewy1y = parseInt(document.p_frm.poulibijh5vfle6zlf32c.value) + parseInt(document.p_frm.poulibijh5vfle6zlf32c.value);</script></TD> <TD valign="top", style="padding-left:3px;padding-top:6px;padding-bottom:3px;">Sõiduki tehasetähis</TD> <TD valign="top", style="padding-left:3px;padding-top:6px;padding-bottom:3px;"><INPUT TYPE="text" NAME="p_vin" SIZE="25" MAXLENGTH="25" id="p_vin"></TD> </TR> <TR> <TD valign="top", style="padding-left:3px;padding-top:3px;padding-bottom:6px;"></TD> <TD valign="top", style="padding-left:3px;padding-top:3px;padding-bottom:6px;"><script>upnm5kflvjh2zlndwkh8 = 335414;</script></TD> <TD valign="top", style="padding-left:3px;padding-top:3px;padding-bottom:6px;"><script>tgmd197lmn3hovcy9la76x6 = 28574;</script><INPUT TYPE="submit" NAME="p_request" VALUE=" Otsi " id="p_request"></TD> </TR> </TABLE> </FORM> <TABLE cellpadding="6px" cellspacing="0px" border="0px" style="table-layout:fixed;"> <TR class="resultHeaderRow"> <TH width="870" valign="middle" align="left" style="padding-left:20px;min-width:845px;max-width:845px;">Teadmiseks</TH> </TR> <TR> <TD COLSPAN="4" width="870" style="word-wrap:break-word;padding-left:20px;min-width:845px;max-width:845px;">Sõiduki liikluskahjude kontrolli päringu tulemus näitab sõiduki osalemist liikluskindlustuse kindlustusjuhtumis. Samuti teavet sõiduki hävinenuks tunnistamise kohta liikluskindlustuse või muu kindlustusjuhtumi tõttu.</TD> </TR> <TR> <TD COLSPAN="4" width="870" style="word-wrap:break-word;padding-left:20px;min-width:845px;max-width:845px;">Andmete otsing toimub liikluskindlustuse registrist ja kindlustusandja poolt hävinuks tunnistatud sõidukite registrist. Neis registrites on teave kindlustusjuhtumite kohta, mida on käsitlenud Eestis tegutsev kindlustusandja. Päringu tulemus ei näita sõidukiga välismaal toimunut ega juhtumeid, millest kindlustusandjat ei ole teavitatud.</TD> </TR> <TR> <TD COLSPAN="4" width="870" style="word-wrap:break-word;padding-left:20px;min-width:845px;max-width:845px;">Näiteks ei sisalda päringu tulemus: a) sõidukiga välismaal toimunud juhtumeid, B) Eestis toimunud sõidukikindlustuse juhtumeid, kui sõiduk ei hävinud ja kahjustada sai vaid kindlustatud sõiduk, c) teavet liiklusõnnetuste kohta, kus kahjustada sai üksnes üks sõiduk.</TD> </TR> <TR> <TD COLSPAN="4" width="870" style="word-wrap:break-word;padding-left:20px;min-width:845px;max-width:845px;">Avaldatavad andmed on informatiivse iseloomuga ega ole mõeldud kasutamiseks muuks otstarbeks. Registrisse esitavad andmeid kindlustusandjad, mistõttu puudub Eesti Liikluskindlustuse Fondil võimalus ja kohustus nende õigsust kontrollida. Eesti Liikluskindlustuse Fond ei vastuta andmete ebaõigsusest tekkinud kahju eest ega andmete alusel vastu võetud otsuste, tegemata jäänud tehingute ja tehtud tehingute tagajärgede eest. Eesti Liikluskindlustuse Fond võtab tarvitusele kõik mõistlikult oodatavad meetmed tagamaks andmete korrektse ning adekvaatse avaldamise.</TD> </TR> </TABLE> </div> <BR> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/274167-curl-cookie-problem/#findComment-1411700 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.