-
-
Save VigneshPT/5278055 to your computer and use it in GitHub Desktop.
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
<?php | |
require_once('pwi/phpQuery.php'); //Including phpQuery Library | |
/** | |
* The input for the REST api is got via "GET" | |
*/ | |
$pnr1 = $_GET['pnr1']; //The first 3 digits of your PNR | |
$pnr2 = $_GET['pnr2']; //Remaining digits | |
$options = array(CURLOPT_POST => true, | |
CURLOPT_FOLLOWLOCATION => true, | |
CURLOPT_COOKIEJAR => "cookies.txt", | |
CURLOPT_COOKIEFILE => "cookies.txt", | |
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1', //Yes, IRCTC website checks for a valid User Agent. | |
CURLOPT_URL => "http://www.indianrail.gov.in/cgi_bin/inet_pnrstat_cgi.cgi", | |
CURLOPT_POSTFIELDS => "lccp_pnrno1={$pnr1}&lccp_pnrno2={$pnr2}&submitpnr=Get+Status", //Postfields trapped from Tamper Data | |
CURLOPT_REFERER => "http://www.indianrail.gov.in/pnr_stat.html", //Safe to include this also. | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_HEADER => false | |
); | |
$ch = curl_init(); | |
curl_setopt_array($ch, $options); | |
$body = curl_exec($ch); //$body contains the source of the resulting page | |
curl_close($ch); | |
phpQuery::newDocument($body); | |
$status = pq('#center_table tr:eq(1) td:eq(2)'); //Grab the status! | |
echo $status; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment