How to fetch search results from another site?

Discussion in 'PHP' started by pankajshr_jpr, Jun 19, 2009.

  1. #1
    Hi, I am newbie and dont know where to post this topic, sorry if wrong posted.
    Actually I want to write a php code which could fetch the flight informations from various airlines sites. These sites have a form in which user can enter information and search the flight. I want to display those results in my site when a user comes to my site and search about flight. For eg. user want to search flights from city-1 to city-2 then he enter the information on my site and my script should search flights according to that information on various airlines sites and display the results with the tag of which ailines is providing this flight.
    Could any one please suggest how to do it?
     
    pankajshr_jpr, Jun 19, 2009 IP
  2. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Do any of these sites provide an API? If so, then this should be trivial. Alternatively, you could use cURL to POST/GET to the airline page, scrape the html, parse it and post it on your site. Even better would be if they provided some format such as XML that you could access and parse.
     
    Louis11, Jun 19, 2009 IP
  3. pankajshr_jpr

    pankajshr_jpr Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    None provides the API nor the XML:(
    also frm cUrl i can connect to other server, but How to search the flight on the another website by sending data using GET/POST method and fetch that search result to my site?
     
    pankajshr_jpr, Jun 19, 2009 IP
  4. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #4
    Have a look at:
    http://us.php.net/curl

    Some of the users have contributed comments that show you how to post/get using cURL.
     
    Louis11, Jun 19, 2009 IP
  5. pankajshr_jpr

    pankajshr_jpr Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have looked at it, but they have not posted about how to search the another site by sending query using GET and POST . Could you explain more about search part?
     
    pankajshr_jpr, Jun 21, 2009 IP
  6. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #6
    It was on the page, you didn't look hard enough ;) Why reinvent the wheel?

    
    <?php
     class mycurl {
         protected $_useragent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1';
         protected $_url;
         protected $_followlocation;
         protected $_timeout;
         protected $_maxRedirects;
         protected $_cookieFileLocation = './cookie.txt';
         protected $_post;
         protected $_postFields;
         protected $_referer ="http://www.google.com";
    
         protected $_session;
         protected $_webpage;
         protected $_includeHeader;
         protected $_noBody;
         protected $_status;
         protected $_binaryTransfer;
         public    $authentication = 0;
         public    $auth_name      = '';
         public    $auth_pass      = '';
    
         public function useAuth($use){
           $this->authentication = 0;
           if($use == true) $this->authentication = 1;
         }
    
         public function setName($name){
           $this->auth_name = $name;
         }
         public function setPass($pass){
           $this->auth_pass = $pass;
         }
    
         public function __construct($url,$followlocation = true,$timeOut = 30,$maxRedirecs = 4,$binaryTransfer = false,$includeHeader = false,$noBody = false)
         {
             $this->_url = $url;
             $this->_followlocation = $followlocation;
             $this->_timeout = $timeOut;
             $this->_maxRedirects = $maxRedirecs;
             $this->_noBody = $noBody;
             $this->_includeHeader = $includeHeader;
             $this->_binaryTransfer = $binaryTransfer;
    
             $this->_cookieFileLocation = dirname(__FILE__).'/cookie.txt';
    
         }
    
         public function setReferer($referer){
           $this->_referer = $referer;
         }
    
         public function setCookiFileLocation($path)
         {
             $this->_cookieFileLocation = $path;
         }
    
         public function setPost ($postFields)
         {
            $this->_post = true;
            $this->_postFields = $postFields;
         }
    
         public function setUserAgent($userAgent)
         {
             $this->_useragent = $userAgent;
         }
    
         public function createCurl($url = 'nul')
         {
            if($url != 'nul'){
              $this->_url = $url;
            }
    
             $s = curl_init();
    
             curl_setopt($s,CURLOPT_URL,$this->_url);
             curl_setopt($s,CURLOPT_HTTPHEADER,array('Except:'));
             curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout);
             curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects);
             curl_setopt($s,CURLOPT_RETURNTRANSFER,true);
             curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation);
             curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation);
             curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation);
    
             if($this->authentication == 1){
               curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass);
             }
             if($this->_post)
             {
                 curl_setopt($s,CURLOPT_POST,true);
                 curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields);
    
             }
    
             if($this->_includeHeader)
             {
                   curl_setopt($s,CURLOPT_HEADER,true);
             }
    
             if($this->_noBody)
             {
                 curl_setopt($s,CURLOPT_NOBODY,true);
             }
             /*
             if($this->_binary)
             {
                 curl_setopt($s,CURLOPT_BINARYTRANSFER,true);
             }
             */
             curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent);
             curl_setopt($s,CURLOPT_REFERER,$this->_referer);
    
             $this->_webpage = curl_exec($s);
                       $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE);
             curl_close($s);
    
         }
    
       public function getHttpStatus()
       {
           return $this->_status;
       }
    
       public function __tostring(){
          return $this->_webpage;
       }
    }
    ?>
    
    PHP:
    Or more simply:

    
    $post_vars = "somevariable=blah&anotherone=123&onemore=test";
    
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_POST,1);
     curl_setopt($ch, CURLOPT_POSTFIELDS,$post_vars);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION  ,1);
     curl_setopt($ch, CURLOPT_HEADER,0); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);
     $Rec_Data = curl_exec($ch);
    
    PHP:
     
    Louis11, Jun 21, 2009 IP
  7. amber.long83

    amber.long83 Active Member

    Messages:
    144
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    78
    #7
    Simply, Witout API. XML and CURL this should not possible at all. you need to modified your actuall requirment :)
     
    amber.long83, Jun 22, 2009 IP
  8. erosraino

    erosraino Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    This could be possible by lease a database like worldspan.
     
    erosraino, Jan 9, 2010 IP
  9. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    If you affiliate with the airlines they should give you all the information you require and an API which you can use to get the data you need
     
    JAY6390, Jan 9, 2010 IP
  10. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #10
    Thier are several methods you could use:

    file_get_contents(), curl

    Perhaps if you posted the direct link to the content you want to fetch, we could help more :).
     
    danx10, Jan 10, 2010 IP