Last active
August 29, 2015 13:56
-
-
Save ruliarmando/9201656 to your computer and use it in GitHub Desktop.
search sriwijaya flight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function actionSearchSriwijaya(){ | |
Yii::import('application.vendors.*'); | |
require_once('curl/curl.php'); | |
require_once('simple_html_dom.php'); | |
$curl = new Curl; | |
$curl->options['CURLOPT_SSL_VERIFYPEER'] = false; | |
$response = $curl->get('https://agent.sriwijayaair.co.id/b2b/secure/home.jsp'); | |
//grab the homepage html | |
$html = str_get_html($response->body); | |
//get the .loginWrapper div | |
$loginWrapper = $html->find('.loginWrapper'); | |
$form = ''; | |
foreach($loginWrapper as $l){ | |
//get the login form | |
$form = $l->find('form', 0); | |
} | |
//get the login form action | |
$form_action = $form->action; | |
$form_action_exploded = explode(';', $form_action); | |
//get the j_session_id of jsp website | |
$j_session_id = isset($form_action_exploded[1]) ? $form_action_exploded[1] : ''; | |
$auth_data = array('j_username'=>'...', 'j_password'=>'...'); | |
$response = ""; | |
if($j_session_id){ | |
$response = $curl->post('https://agent.sriwijayaair.co.id/b2b/secure/j_security_check;'.$j_session_id, $auth_data); | |
}else{ | |
$response = $curl->post('https://agent.sriwijayaair.co.id/b2b/secure/', $auth_data); | |
} | |
$departDate = explode('-', $_POST['SearchFlightForm']['depart']); | |
$departDate1 = $departDate[2]; | |
$monthPortion = intval($departDate[1]) - 1; | |
$yearPortion = $departDate[0]; | |
$departDate2 = $monthPortion.'-'.$yearPortion; | |
$isReturn = $_POST['SearchFlightForm']['trip'] == 'o' ? 'false' : 'true'; | |
$search_data = array( | |
'isReturn'=>$isReturn, | |
'from'=>$_POST['SearchFlightForm']['from'], | |
'to'=>$_POST['SearchFlightForm']['to'], | |
'departDate1'=>$departDate1, | |
'departDate2'=>$departDate2, | |
'adult'=>$_POST['SearchFlightForm']['adult'], | |
'child'=>$_POST['SearchFlightForm']['child'], | |
'infant'=>$_POST['SearchFlightForm']['infant'], | |
'returndaterange'=>'0', | |
'Submit'=>'Search', | |
); | |
$response = $curl->post('https://agent.sriwijayaair.co.id/b2b/secure/AvailabilityAction', $search_data); | |
//we will grab the table with id: table_go | |
//table with id: table_back for return trip | |
$html = str_get_html($response->body); | |
$table_go = $html->find('#table_go', 0); | |
$table_go->class = 'table table-bordered table-condensed table-striped'; | |
$table_go->cellspacing = null; | |
echo $table_go->outertext; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment