PHP - Curl And Facebook Problem
I have this code
curl_setopt($ch, CURLOPT_POST, 0); curl_setopt($ch, CURLOPT_URL, $link); $wall = curl_exec($ch); but the $link is a facebook wall page that takes a couple of seconds to load fully. and you have to scroll down the page before more loads or you have to click older posts when i run the script the $wall doesnt have the full page. Is there a way that i can delay the $link from saving the file so that it reads more of the page?? Similar TutorialsHey guys, Been trying to get my head around curl over the past month, I need help with loading one of Facebook's Applications. I need the script to: 1) Log into Facebook. 2) Load up the application. 3) Load up the application's iFrame. I've got steps 1 + 2 down, so it logs into Facebook and loads up the application alright, but when it comes to loading up the specific application's iframe, it re-directs me to log in again. I am 99% sure it's something to do with cookies because if you log in locally and load up the iframe url it has no problem loading up the app. (Iframe URL: http://mobsters-fb-apache-dynamic-lb.playdom.com/prod_facebook/facebook/mobsters_v1/facebook_iframe.php?track=bookmark) Here is my current code: (Running it in apache) And also I am really new to curl and am pretty much learning on the go so please excuse any obvious errors $Email = strip_tags(str_replace(' ', '', $_POST['email'])); $Password = strip_tags(str_replace(' ', '', $_POST['password'])); $MobstersURL = "http://apps.facebook.com/mobstersapp/index.php?track=bookmark&ref=bookmarks&count=0"; $FBlogin = 'https://www.facebook.com/login.php?login_attempt=1'; $Data = 'charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&lsd=vuCfh&locale=en_US&email='.urlencode($Email).'&pass='.urlencode($Password).'&default_persistent=0&charset_test=%E2%82%AC%2C%C2%B4%2C%E2%82%AC%2C%C2%B4%2C%E6%B0%B4%2C%D0%94%2C%D0%84&lsd=vuCfh'; $Cookie = "cookie.txt"; $fp = fopen($Cookie,'wb'); $agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7"; //login to facebook $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$FBlogin); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_COOKIEFILE, $Cookie); curl_setopt($ch, CURLOPT_COOKIEJAR, $Cookie); curl_setopt($ch, CURLOPT_REFERER, $FBlogin); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_POSTFIELDS, $Data); $Excecute = curl_exec($ch); //echo $Excecute; //load up mobsters then display it curl_setopt($ch, CURLOPT_URL,$MobstersURL); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_REFERER, "http://www.facebook.com/?ref=logo"); curl_setopt($ch, CURLOPT_COOKIEFILE, $Cookie); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $LoadMobsters = curl_exec($ch); echo $LoadMobsters; //load up mobsters in iframe THIS IS WHERE I'M STUCK curl_setopt($ch, CURLOPT_URL, "http://mobsters-fb-apache-dynamic-lb.playdom.com/prod_facebook/facebook/mobsters_v1/facebook_iframe.php?track=bookmark"); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_COOKIEFILE, $Cookie); curl_setopt($ch, CURLOPT_REFERER, "http://apps.facebook.com/mobstersapp/index.php?track=bookmark&ref=bookmarks&count=0"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 1); $Load_iFrame = curl_exec($ch); echo $Load_iFrame; // This is where I noticed it wasn't working since instead of loading up the iframe, it brought me back to facebook to log in. So yeah I need some help in loading up the iframe since that is where I need to grab important data. Any help would be much appreciated, and yes, I've been to http://php.net/manual/en/book.curl.php a billion times which is why I've come here where the pro's are for help Thanks. I'm trying to create a "Post" link that when clicked, will allow the user to post information onto their wall. I have figured out how to enable the proper permissions but the problem is one of two things: My code: <form method='post' action='https://graph.facebook.com/me/feed'> <input type='text' name='message' id='message' /> <input type='text' name='access_token' id='access_token' value='<?php echo $session['access_token'];?>' /> <input type='submit' /> </form> The above DOES post onto my wall on behalf of my website, however, the browser attempts to download the url file for some reason and I get a popup saying "Cannot download file for whatever reason". I've looked at Facebook's Open Graph API and found this: curl -F 'access_token=...' \ -F 'message=Check out this funny article' \ -F 'link=http://www.example.com/article.html' \ -F 'picture=http://www.example.com/article-thumbnail.jpg' \ -F 'name=Article Title' \ -F 'caption=Caption for the link' \ -F 'description=Longer description of the link' \ -F 'actions={"name": "View on Zombo", "link": "http://www.zombo.com"}' \ -F 'privacy={"value": "ALL_FRIENDS"}' \ -F 'targeting= {"countries":"US","regions":"6,53","locales":"6"}' \ https://graph.facebook.com/me/feed So my question is: How do I fix my current code to prevent the downloading of the url file OR how do I even use Facebook's code? I've reseacrhed Curl and I don't understand how to translate the code into php (preferably) or javascript. Hi.
I'm working on some program. It adds new posts to facebook profiles, fanpages and groups. Everything works well, but when I want to create image uploading it just doesn't work (whitepage as result + file probably isn't even send, because of very short sending time).
Multipart form sniffed with Firefox looks like this.
Spoiler
Content-Type: multipart/form-data; boundary=---------------------------13742240526862 Content-Length: 788662 -----------------------------13742240526862 Content-Disposition: form-data; name="fb_dtsg" AQGlrKAR9le4 -----------------------------13742240526862 Content-Disposition: form-data; name="charset_test" â¬,´,â¬,´,æ°´,Ð,Ð -----------------------------13742240526862 Content-Disposition: form-data; name="file1"; filename="h.jpg" Content-Type: image/jpeg FILE_CONTENTS_HERE -----------------------------13742240526862 Content-Disposition: form-data; name="file2"; filename="" Content-Type: application/octet-stream -----------------------------13742240526862 Content-Disposition: form-data; name="file3"; filename="" Content-Type: application/octet-stream -----------------------------13742240526862 Content-Disposition: form-data; name="caption" -----------------------------13742240526862 Content-Disposition: form-data; name="return_uri" /groups/880573151971764?view=group&fc=photo_upload_success -----------------------------13742240526862 Content-Disposition: form-data; name="return_uri_error" https://m.facebook.com/photos/upload/?target_id=880573151971764&upload_source=composer&cwevent=intent_media&ctype=inline&referrer=group&session_id=5f737e58-0e23-4270-a8af-8bfa1100f3c5&refid=18 -----------------------------13742240526862 Content-Disposition: form-data; name="target" 880573151971764 -----------------------------13742240526862 Content-Disposition: form-data; name="ref" m_upload_pic -----------------------------13742240526862 Content-Disposition: form-data; name="album_fbid" -----------------------------13742240526862 Content-Disposition: form-data; name="csid" 5f737e58-0e23-4270-a8af-8bfa1100f3c5 -----------------------------13742240526862 Content-Disposition: form-data; name="ctype" advanced -----------------------------13742240526862 Content-Disposition: form-data; name="referrer" group -----------------------------13742240526862 Content-Disposition: form-data; name="is_old_composer" 1 -----------------------------13742240526862-- My game on facebook is being displayed in the facebook application iframe. When users register in firefox or google chrome everything is fine and to a certain extent in IE as well. However, when logging into the game, through the browsers the game loads fine except when loaded in IE.... Basically i am using a session to state that the game is currently in facebook mode: Code: [Select] <?php session_start(); $_SESSION['isface'] = 1; include("game.php"); ?> All is good until it hits this code: Code: [Select] <html> <frameset cols="130" noresize border=0> <frame src="nav.php" name="nav"> <frame src="hq.php" name="main"> </frameset> </html> The frames then output error message: Code: [Select] <?php if ($isface !="1") { if (sha1($info[4]) != $pass) { mysql_close(); echo $isface; die("<br><br><center><body bgcolor='#000000'><b><font color='#FFFFFF' face='Verdana' size='2pt'>{$isface} Your username cannot be found or password doesnt match</font></b></center></body></html>"); } } ?> essentially the game is using cookies for authentication on the main site, but since this is facebook this is not needed so it SHOULD skip this check and proceed with using the facebook details as the login. this is only happening in IE... i dont get it. any ideas? This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=309715.0 Hi i have a facebook login social plugin made but my ? is why do i get symbols in my url link ?. I login with the plugin to facebook but when page returns me back to my site i have symbols at the end of url. Like this http://www.games-flash.co.uk/#_=_ Ps sry if i have made this post in wrong section. This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=347238.0 Hey there I'm trying to gather a users Facebook info and use that to create a user account for them on my database. My code works perfectly for the first person who links his Facebook account with my site and adds all the user info to the database. After that with any other users it will display the logged in Facebook users name with their profile pic. The problem arises when it tries to add this person to the mysql database. It returns the error "An error has occurred and we are unable to sync your Facebook account." Before the <head> Code: [Select] <?php define('FACEBOOK_APP_ID', 'imagine_app_id_here'); define('FACEBOOK_SECRET', 'imagine_secret_here'); function get_facebook_cookie($app_id, $application_secret) { $args = array(); parse_str(trim($_COOKIE['fbs_' . $app_id], '"'), $args); ksort($args); $payload = ''; foreach ($args as $key => $value) { if ($key != 'sig') { $payload .= $key . '=' . $value; } } if (md5($payload . $application_secret) != $args['sig']) { return null; } return $args; } $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET); ?> In the <body> Code: [Select] <?php if ($cookie) { //###cookie is set, user is logged in $user = json_decode(file_get_contents('https://graph.facebook.com/'.$cookie['uid'])); define('INCLUDE_CHECK',true); require("connect.php"); $fbookid = $user->{'id'}; $fbookname = $user->{'name'}; $query = mysql_query("SELECT * FROM tz_members WHERE facebook_id='$fbookid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ echo "<font color='#FF0000'>You are logged in through Facebook.</font>"; } else { mysql_query("INSERT INTO tz_members(facebook_id,usr,regIP,dt) VALUES( '".$fbookid."', '".$fbookname."', '".$_SERVER['REMOTE_ADDR']."', NOW() )"); $query = mysql_query("SELECT * FROM tz_members WHERE facebook_id='$fbookid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ echo "<font color='#FF0000'>Your Facebook account has been synced with our user database.</font>"; } else { echo "<font color='#FF0000'>An error has occured and we are unable to sync your Facebook account.</font>"; } mysql_close(); } echo '<img src="http://graph.facebook.com/'.$user->{'id'}.'/picture" alt="'.$user->{'name'}.'"/>'; echo $user->{'name'}; echo '<fb:login-button perms="email,user_birthday" onlogin="window.location.reload(true);" autologoutlink="true"></fb:login-button>'; } else { //###user is not logged in, display the Facebook login button echo '<fb:login-button perms="email,user_birthday" autologoutlink="true"></fb:login-button>'; } ?> Javascript: Code: [Select] <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.login', function(response) { window.location.reload(); }); </script> Any help would be greatly appreciated! I'm trying to submit to my site using this script that I made: <?php session_start(); $title = "<title>CS</title>"; $url = "http://cheatskape.com/wtag/sendchat.php"; $token = md5(uniqid(rand(), true)); $_SESSION['token'] = $token; $ch = curl_init(); //Initalize a new cURL session $name = "PROBLEM"; $msg = "LOL"; $postfields = "token=".$token."&name=".$name."&url=&message=".$msg.""; echo $title; //set the title of the window curl_setopt($ch, CURLOPT_POST, 1); //set the type, curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); //and what fields to use curl_setopt($ch, CURLOPT_URL, $url);//Set the URL to use curl_exec($ch); //execute it echo "<br /><br /><br />"; print_r(curl_getinfo($ch)); //Print info of the cURL execution curl_close($ch); //Close our current cURL session ?> However, it refuses to post.. What am I doing wrong? This is my first time using cURL the curl info shows me this: Quote Array ( [url] => http://cheatskape.com/wtag/sendchat.php [content_type] => text/xml; charset=UTF-8 [http_code] => 200 [header_size] => 439 [request_size] => 208 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.39 [namelookup_time] => 0 [connect_time] => 0.188 [pretransfer_time] => 0.188 [size_upload] => 68 [size_download] => 2039 [speed_download] => 5228 [speed_upload] => 174 [download_content_length] => 2039 [upload_content_length] => 0 [starttransfer_time] => 0.39 [redirect_time] => 0 [certinfo] => Array ( ) ) Hi,
I'd stumbled upon a problem around doing curl on an asp website which use cookie.
I use username n session id to determine the cookie file, on a case when a second browser open up it should have different session id, hence it may create new cookies instead of using the active previously-made cookie file, please do correct me if I'm wrong.
So question is....how to detect a user is logged or not in such situation ?
Or perhaps how is the proper way to determine a cookie file in such situation ?
Thanks in advance,
Hi I made a curl and don't know what to do with the string I got back, I would need the id and the name of each, should I explode, don't know how to do that, here is what I got as answer: Quote string(596) "{"data":[{"name":"Esoterik Forum","category":"Community","id":"180883525283576"},{"name":"Hellsehen und Wahrsagen","category":"Company","id":"177967172214131"},{"name":"Spirituelle Lebensberatung","category":"Website","id":"164411270264299"},{"name":"Esoterik","category":"Website","id":"164524456919432"},{"name":"Kartenlegen und Hellsehen","category":"Company","id":"173933135951523"},{"name":"Exchange","category":"Application","id":"190533567633445"},{"name":"Astrologie","category":"Website","id":"164928140213920"},{"name":"Esoterik Forum","category":"Application","id":"184577371575355"}]}" Hey guys, I have developed an script which opens or fetches a page using curl, now the problem is the url i am trying to fetch follows lot of redirects(say 302) and in between it stores several cookies also which i don't know or guess. So i was just thinking, is there any way so that i can automatically store the cookies in a particular file which server wants to store, and let it sent in request as per the asking of a request in request header? I hope you would have got what i mean to say here, for example suppose i want to open http://www.example.com and now that above url faces lot of redirects probably 5-6 and then ends up on http://www.test.com now in between it stores some cookies in clients computer and then it fetches them also. Since i don't know which cookie it gonna store, I must put this responsibility to PHP itself to store and send the requested cookies in request headers. Also i want to send the referrer also in request header, and it must be the last page that or request sent to the server, no matter whether it's in betwen redirects or to the final page. In short i mean to create the complete emulation of browser for this URL. Hello, hello i need use curl with proxy. but i get "undefined variable offset 1" error . here is the standart code i use. please help me about it thanks curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_USERAGENT, $agent); good day dear community, i am workin on a Curl loop to fetch multiple pages: i have some examples - and a question: Example: If we want to get information from 3 sites with CURL we can do it like so: $list[1] = "http://www.example1.com"; $list[2] = "ftp://example.com"; $list[3] = "http://www.example2.com"; After creating the list of links we should initialize the cURL multi handle and adding the cURL handles. $curlHandle = curl_multi_init(); for ($i = 1;$i <= 3; $i++) $curl[$i] = addHandle($curlHandle,$list[$i]); Now we should execute the cURL multi handle retrive the content from the sub handles that we added to the cURL multi handle. ExecHandle($curlHandle); for ($i = 1;$i <= 3; $i++) { $text[$i] = curl_multi_getcontent ($curl[$i]); echo $text[$i]; } In the end we should release the handles from the cURL multi handle by calling curl_multi_remove_handle and close the cURL multi handle! If we want to another Fetch of sites with cURL-Multi - since this is the most pretty way to do it! Well I am not sure bout the string concatenation. How to do it - Note I want to fetch several hundred pages: see the some details for this target-server sites - /(I have to create a loop over several hundred sites). * siteone.example/?show_subsite=9009 * siteone.example/?show_subsite=9742 * siteone.example/?show_subsite=9871 .... and so on and so forth Question: How to appy this loop into the array of the curl-multi? <?php /************************************\ * Multi interface in PHP with curl * * Requires PHP 5.0, Apache 2.0 and * * Curl * ************************************* * Writen By Cyborg 19671897 * * Bugfixed by Jeremy Ellman * \***********************************/ $urls = array( "siteone", "sitetwo", "sitethree" ); $mh = curl_multi_init(); foreach ($urls as $i => $url) { $conn[$i]=curl_init($url); curl_setopt($conn[$i],CURLOPT_RETURNTRANSFER,1);//return data as string curl_setopt($conn[$i],CURLOPT_FOLLOWLOCATION,1);//follow redirects curl_setopt($conn[$i],CURLOPT_MAXREDIRS,2);//maximum redirects curl_setopt($conn[$i],CURLOPT_CONNECTTIMEOUT,10);//timeout curl_multi_add_handle ($mh,$conn[$i]); } do { $n=curl_multi_exec($mh,$active); } while ($active); foreach ($urls as $i => $url) { $res[$i]=curl_multi_getcontent($conn[$i]); curl_multi_remove_handle($mh,$conn[$i]); curl_close($conn[$i]); } curl_multi_close($mh); print_r($res); ?> I look forward to your ideas. Code: [Select] <html> <title>MyBB PM Exporter</title> <body> <form action ="<?php $_SERVER['PHP_SELF'] ?>" method="post"> URL to site: <input type ="text" name="site" value='community.mybb.com' /><br> Full path to user:pwd list: <input type ="text" name="path" value='/home/www/list.txt' /><br> <input type = "submit" value="Export" /> </form> </body> </html> <?php if(isset($_POST['path']) && isset($_POST['site'])) { $list = $_POST['path']; $url = $_POST['site']; $file = file($list); foreach($file as $line){ $explode = explode(":",$line); $username = $explode[0]; $password = $explode[1]; $crl = curl_init(); curl_setopt($crl, CURLOPT_URL, $url."/member.php"); curl_setopt($crl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); curl_setopt($crl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt"); curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($crl, CURLOPT_POST, 1); // This array will hold the field names and values. $postdata=array( "username"=>"$username", "password"=>"$password", "remember"=>"no", "submit"=>"Login", "action"=>"do_login", "url"=>$url."/member.php" ); // Tell curl we're going to send $postdata as the POST data curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata); $result=curl_exec($crl); $find_key = preg_match('/var my_post_key = "(.*?)"/',$result,$match); $my_post_key = $match[1]; curl_setopt($crl, CURLOPT_URL, $url."/private.php"); curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($crl, CURLOPT_POST, 1); // This array will hold the field names and values. $postdata=array( "my_post_key" => $my_post_key, "exportfolders[]" => "all", "dayway" => "disregard", "exportunread" => "1", "deletepms" => "0", "exporttype" => "html", "action" => "do_export", "submit" => "Export Private Messages" ); curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata); $fh = fopen($username.".html", 'w'); curl_setopt($crl, CURLOPT_FILE, $fh); curl_exec($crl); fclose($fh); curl_close($crl); } } ?> So , basically this code just opens the file where username:password is located and then it logins to community.mybb.com with each combination in that file and saves the content of pm's of logged in user. Problem is that this script allways saves pm's of only one user and it saves other usernames pm's but with the same content of the first user. Hi everybody ! I have this current problem .. I need to login into a website via cUrl .. website : www.v-tac [dot] ro/ Now based on the headers and based on the input fields I wrote a php function, but I hit a wall with the token . HEADERS : username=username&password=password&Submit=Conectare&option=com_users&task=user.login&return=aW5kZXgucGhwP0l0ZW1pZD0yMTY%3D&0dbf64fe20e2395a7d72ed5b64b3cf7c=1FORM FIELDS - copy paste - this is the login form <fieldset class="userdata"> <p id="form-login-username"> <label for="modlgn-username">Nume Utilizator</label> <input id="modlgn-username" type="text" name="username" class="inputbox" size="18"> </p> <p id="form-login-password"> <label for="modlgn-passwd">Parola</label> <input id="modlgn-passwd" type="password" name="password" class="inputbox" size="18"> </p> <p id="form-login-remember"> <label for="modlgn-remember">Retine utilizator</label> <input id="modlgn-remember" type="checkbox" name="remember" class="inputbox" value="yes"> </p> <input type="submit" name="Submit" class="button" value="Conectare"> <input type="hidden" name="option" value="com_users"> <input type="hidden" name="task" value="user.login"> <input type="hidden" name="return" value="aW5kZXgucGhwP0l0ZW1pZD0yMTY="> <input type="hidden" name="11b09608b3184e6258012d44846c81ed" value="1"> </fieldset>And this is the function I wrote to do the cUrl login : function login_to_website($targetURL){ global $browser_user_agent; if(empty($targetURL)) { return; } if(empty($login_url)) { $login_url = $targetURL; } $url = $login_url; $login_user = "loginusername"; $login_password = "loginpassword"; $thetoken = "this-is-my-problem-the-token-from-the-hidden-input"; $post_data = array(); $post_data['username'] = "$login_user"; $post_data['password'] = "$login_password"; $post_data['Submit'] = "Conectare"; $post_data['option'] = "com_users"; $post_data['task'] = "user.login"; $post_data['return'] = "aW5kZXgucGhwP0l0ZW1pZD0yMTY%3D"; $post_data[$thetoken] = "1"; $postthis = http_build_query($post_data); $login = curl_init(); curl_setopt($login, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookie.tmpz"); curl_setopt($login, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.tmpz"); curl_setopt($login, CURLOPT_VERBOSE, true); curl_setopt($login, CURLOPT_URL, $url); curl_setopt($login, CURLOPT_USERAGENT, random_user_agent()); curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($login, CURLOPT_POST, TRUE); $timeout = 5; curl_setopt( $login, CURLOPT_CONNECTTIMEOUT, $timeout ); curl_setopt( $login, CURLOPT_TIMEOUT, $timeout ); curl_setopt( $login, CURLOPT_MAXREDIRS, 10 ); curl_setopt($login, CURLOPT_POSTFIELDS, $postthis); // POST vars curl_setopt($login, CURLOPT_HEADER, 0); // debug headers sent - 1 $data = curl_exec ($login); curl_setopt($login, CURLOPT_URL, $targetURL); $datax = curl_exec ($login); return $datax; // close cURL resource, and free up system resources curl_close($login); }The problem is this the last array input. the token is generated each time the page is loaded, located on the page as an input hidden field . So the question is how do I get a fresh token that will work ? Also I have tried to get the token with a xpath extract like this : $htmlx = file_get_contents('http://www.v-tac.ro'); $htmlx = mb_convert_encoding($htmlx, 'UTF-8', mb_detect_encoding($htmlx)); //make sure this is utf8 if(!strlen($htmlx)) {echo "No HTML here . stoping execution ."; return;} $doc = new DomDocument; @$doc->loadHTML($htmlx); $xpath = new DOMXPath($doc); echo $xpath->query('//fieldset[@class="userdata"]/input[5]')->item(0)->getAttribute("name"); $thetoken = $xpath->query('//fieldset[@class="userdata"]/input[5]')->item(0)->getAttribute("name");Help !? Hello,
I want to download flight from Wizzair page.
I've checked all headers which are sended when browser "create" request (the same which Ryanair few months ago).
It looks like this in my browser: Hi,
Well, I've been wondering if I can get answer to my problem here...
I'd used curl to fetch information from other site and then I need to parse the data to be displayed in our own. However I found something odd...I can't parse it to get what I want...however should I put the result into a html file, n parse the file itself...it's fine.
Basically I just need to find whether a word/phrase is there or not...n I'm using preg_match to do it so far. Since the time it first arises...I'd been googling n saw some posts...something similar to how regex is doing poorly in doing such thing...
However it does work when I just make a php file just to do that regex from the curl-result html file, it just not work on the actual php file which handle the process even if it's from the same curl-result html file. FYI, I'm using codeigniter.
I wonder if it got something to do with codeigniter or something...or is there any other better way to parse a html file from a curl result. In my opinion it's just the same...be it a curl result or just a normal html...so I really can't figure out where it went wrong.
I appreciate if there's anyone who can shed a light on this problem, even a little bit is a great help to me
Thanks in advance,
Hello, First of all ,I have been a regular reader of the forum and it has increased my knowledge in the PHP a lot. Till now i had just been a guest user and used to go through the queries and tips posted here. Today , for the first time i am posting on the forum Coming to a problem: I have to design a function for a client from travel domain. Where he wants the script/function to go and extract data from an airline website on the available fare for a specific date and destination. The problem is that only a part of fare(Base fare) is visible on the site and you have to select one of the given flight option(s) (after selecting the option through AJAX the full fare is displayed on the same page on the left hand site) to get the complete fare including fare and surcharges. Now i want my function/script to extract the full fare for all the available flight options. I have written the below piece of code. But its not efffective as it gets only the base fare part of the result page and not the complete fare.. The airline booking url is : http://book.spicejet.com/skylights/cgi-bin/skylights.cgi My code: //---- Spicejet start // ENGINE URL http://book.spicejet.com/skylights/cgi-bin/skylights.cgi?page=homecomp //Taking some sample search data - just to test the script $event="search" ; $module="SB" ; $page="SEARCH" ; $mode="empty" ; $travel="1" ; // ONE WAY OR 2 WAY $from1="HYD" ; $to1="DEL" ; $departDay1="13" ; $departDay2=""; $departMonth1="201010" ; $ADULT="1" ; $CHILD="0" ; $INFANT="0" ; $toCity1="DEL" ; $numberMarkets="1" ; // the page needs data in POST form $curlPost = 'event=' . urlencode($event) . '&module=' . urlencode($module) .'&page=' . urlencode($page) .'&mode=' . urlencode($mode) .'&travel=' . urlencode($travel) .'&from1=' . urlencode($from1) .'&to1=' . urlencode($to1) .'&departDay1=' . urlencode($departDay1) .'&departMonth1=' . urlencode($departMonth1) .'&ADULT=' . urlencode($ADULT) .'&CHILD=' . urlencode($CHILD) .'&INFANT=' . urlencode($INFANT) .'&toCity1=' . urlencode($toCity1) .'&numberMarkets=' . urlencode($numberMarkets).'&submitSearch=submitSearch'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://book.spicejet.com/skylights/cgi-bin/skylights.cgi'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 2.0.50727; .NET CLR 1.1.4322)"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); $data = curl_exec($ch); curl_close($ch); echo($data); Also one more query Is there something like beautiful soup (As in Python) to parse the data. I want to extract the flight timing and total price from the page and insert into a database. Thanxs in advance |