Skip to content

Instantly share code, notes, and snippets.

@VigneshPT
Forked from aarvay/gist:1341918
Created March 30, 2013 19:36
Show Gist options
  • Save VigneshPT/5278055 to your computer and use it in GitHub Desktop.
Save VigneshPT/5278055 to your computer and use it in GitHub Desktop.
<?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