Some information on booking flights with Sabre

A lot of people contacted me asking about how Sabre works, etc. So, I decided to post this here. The way it works is:

  1. You sign up with Sabre for a web services account and you they will give you an IPCC, username and passwrord that you use for communicating with their web services.You will send over the username and password for only authentication request. However, you will use your IPCC in all the requests you make.
  2. Your initial request should be a SessionCreate request. You will provide your username and password in it. Upon success, you will receive a binary token. You will use this token in all the subsequent requests you make.
  3. Your subsequent requests will depend on what you want to do and the services you have access to. Sabre has multiple flight services that you can communicate with. You will need to contact them, explain your needs and ask what service will be best for you. LowFareSearch and BargainFinder are probably the ones that are most used.
  4. After you are done selecting the flight, etc. You will send a request to AirBook (if I remember the name correctly) to book a flight. And, there’s other services you might want to use to pass passenger information, etc.
  5. After you are done, you end the session with a call to SessionCloseRQ.

When you get an account with Sabre, you will be able to look at request and response formats for  the for the web services over here:



PHP and Sabre

What is Sabre?

Sabre is a company that has data of all flight schedules, etc. And, using their system, you can book flights, hotels, rent cars, etc.

Getting PHP to talk with Sabre

I tried PHP Soap and nuSoap. They both didn’t work for me because of their limitations. So I ended up writing a small script of my own that talks with Sabre for me after I realized that the headers being sent by all the SOAP libraries I tried, were not compatible with Sabre’s web services.

Sabre checks the “Content-Type” header in your request. If that is not “text/xml”, you will always get an error, even if your xml is correct.

Here’s a little piece of code that should help with the transport part.  I will leave the generation of XML to you.

 * Sabre class (for connecting to Sabre web services)
 * @author Moazzam Khan 
 * @version $Id$
class Sabre {
	public $host;
	public $port;
	public $timeout;

	public function Sabre()
		$this->timeout = 30;
	public function makeRequest($body)
		$header = "POST /websvc HTTP/1.1\r\n"
					. "Host: {$this->host}:{$this->port}
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Content-Type: text/xml
Content-Length: ".strlen($body)."
Pragma: no-cache
Cache-Control: no-cache";
		$fp = fsockopen("ssl://".$this->host, $this->port, $errno, $errstr, $this->timeout);
			print "SOCKET ERROR $errstr ($errno)\n";
		} else {
				//send the request
				fputs($fp, $header."\r\n\r\n".$body, strlen($header."\r\n\r\n".$body));
				stream_set_timeout($fp, 30);
				stream_set_blocking ($fp, 1);
				while (!feof($fp)) {
					$line = fread($fp, 2048);
					if (trim(strlen($line)) < 10) continue;
					$output .= $line;
		$ret = explode("\r\n\r\n", $output);
		$ret = explode("\r\n", $ret[1]);
		for ($i=0; $i