Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Welcome extends CI_Controller {
- /**
- * Index Page for this controller.
- *
- * Maps to the following URL
- * http://example.com/index.php/welcome
- * - or -
- * http://example.com/index.php/welcome/index
- * - or -
- * Since this controller is set as the default controller in
- * config/routes.php, it's displayed at http://example.com/
- *
- * So any other public methods not prefixed with an underscore will
- * map to /index.php/welcome/<method_name>
- * @see http://codeigniter.com/user_guide/general/urls.html
- */
- public function index()
- {
- }
- 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
- {
- $post = http_build_query( $data );
- $header = "Accept-language: en\r\n".
- "Content-Type: application/x-www-form-urlencoded\r\n" .
- "Content-Length: " . strlen( $post ) .
- "\r\nUser-agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n";
- if($extraHeaders) {
- foreach($extraHeaders as $headerN => $val) {
- $header = $header.$headerN.': '.$val."\r\n";
- }
- }
- if($cookies) {
- $cookieArr = array();
- foreach($cookies as $cookie => $value) {
- array_push($cookieArr,$cookie.'='.$value);
- }
- $cookieStr = "Cookie: ".implode('; ',$cookieArr)."\r\n";
- $header = $header.$cookieStr;
- }
- $context = stream_context_create( array(
- "http" => array(
- "method" => "POST",
- "header" => $header,
- "content" => $post
- )
- ) );
- $page = file_get_contents( $url, false, $context );
- return $page;
- }
- public function getBusesTo($to="Kottayam",$startTime = "00:00",$endTime = "11:30") {
- $this->load->helper('simple_html_dom_helper');
- $url = "http://www.vyttilamobilityhub.com/bus-timing";
- $from = "Vytilla";
- $placeId = 158;
- $html = $this->send_post($url,array('starttime'=>$startTime,'endtime'=>$endTime,'placeid'=>$placeId));
- //echo '<textarea>'.$html.'</textarea>';
- $html = str_get_html($html);
- $tds = $html->getElementsByTagName('td');
- foreach($tds as $td) {
- echo $td->nodeValue;
- echo "<br />";
- }
- //echo "<code>";
- //print_r($table);
- }
- }
- /* End of file welcome.php */
- /* Location: ./application/controllers/welcome.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement