Advertisement
Guest User

Untitled

a guest
Apr 10th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Welcome extends CI_Controller {
  4.  
  5.     /**
  6.      * Index Page for this controller.
  7.      *
  8.      * Maps to the following URL
  9.      *      http://example.com/index.php/welcome
  10.      *  - or -  
  11.      *      http://example.com/index.php/welcome/index
  12.      *  - or -
  13.      * Since this controller is set as the default controller in
  14.      * config/routes.php, it's displayed at http://example.com/
  15.      *
  16.      * So any other public methods not prefixed with an underscore will
  17.      * map to /index.php/welcome/<method_name>
  18.      * @see http://codeigniter.com/user_guide/general/urls.html
  19.      */
  20.     public function index()
  21.     {  
  22.                
  23.     }
  24.    
  25. public function send_post( $url, $data ,$cookies='',$extraHeaders = '') //sends data array(param=>val,...) to the page $url in post method and returns the reply string
  26. {
  27.     $post    = http_build_query( $data );
  28.     $header =  "Accept-language: en\r\n".
  29.                 "Content-Type: application/x-www-form-urlencoded\r\n" .
  30.                 "Content-Length: " . strlen( $post ) .
  31.                 "\r\nUser-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n";
  32.  
  33.     if($extraHeaders) {
  34.         foreach($extraHeaders as  $headerN  => $val) {
  35.             $header = $header.$headerN.': '.$val."\r\n";
  36.         }
  37.  
  38.     }
  39.     if($cookies) {
  40.         $cookieArr = array();
  41.         foreach($cookies as  $cookie  => $value) {
  42.             array_push($cookieArr,$cookie.'='.$value);
  43.         }
  44.         $cookieStr = "Cookie: ".implode('; ',$cookieArr)."\r\n";
  45.         $header = $header.$cookieStr;
  46.     }
  47.     $context = stream_context_create( array(
  48.          "http" => array(
  49.              "method" => "POST",
  50.             "header" => $header,
  51.             "content" => $post
  52.         )
  53.     ) );
  54.     $page    = file_get_contents( $url, false, $context );
  55.     return $page;
  56. }
  57.     public function getBusesTo($to="Kottayam",$startTime = "00:00",$endTime = "11:30") {
  58.         $this->load->helper('simple_html_dom_helper');
  59.         $url = "http://www.vyttilamobilityhub.com/bus-timing";
  60.         $from = "Vytilla";
  61.         $placeId = 158;
  62.        
  63.         $html =  $this->send_post($url,array('starttime'=>$startTime,'endtime'=>$endTime,'placeid'=>$placeId));    
  64.         //echo '<textarea>'.$html.'</textarea>';
  65.         $html = str_get_html($html);
  66.         $tds = $html->getElementsByTagName('td');
  67.         foreach($tds as $td) {
  68.            
  69.             echo $td->nodeValue;
  70.             echo "<br />";
  71.         }
  72.        
  73.         //echo "<code>";
  74.         //print_r($table);
  75.        
  76.     }
  77. }
  78.  
  79. /* End of file welcome.php */
  80. /* Location: ./application/controllers/welcome.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement