Skip to content

Instantly share code, notes, and snippets.

@aarvay
Created November 5, 2011 19:38
Show Gist options
  • Save aarvay/1341918 to your computer and use it in GitHub Desktop.
Save aarvay/1341918 to your computer and use it in GitHub Desktop.
A RESTful API to check the PNR Status
<?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;
@ahmadasjad
Copy link

ahmadasjad commented Jun 22, 2017

Useless now as it's totally changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment