KTMB (Keretapi Tanah Melayu Berhad) Station Schedule Checker in PHP via MyRailTime 2.0's API

Overview

KTM Station Schedule Checker & Journey Planner in Web Form (PHP)

KTMB (Keretapi Tanah Melayu Berhad) Station Schedule Checker & Journey Planner in Web Form , written with PHP.

Why I need to use this instead of MyRailTime2.0 App?

I personally feel that MyRailTime2.0 App isn't providing a good experience for me , and their web page form of MyRailTime2.0 took lots of time to load their webpacked vendor JS file, makes the loading time to 5 seconds and above , but the API only uses 100ms+ to get the responses.

Requirements

  1. PHP 7.4 and above
  2. Redis and Redis PHP Extension installed (For Rate Limit purposes)
  3. A VPS / Computer / Server that have a stable Internet Connection and allowed to access MyRailTime 2.0's API Endpoint (myrailtime.ktmb.com.my:8080)
  4. Nginx / Apache / Any web server with PHP configured install and running

Deployment

  1. Download the source code and extract to the designated folder on ur web server root folder.
  2. Make sure Redis and Redis PHP Extension installed.
  3. Make sure PHP is preconfigured with your web server.
  4. Expose it to public and you are up and running!.

Data Sources

  • MyRailTime 2.0 APP on version 1.8 (API Endpoint Grabbed via Proxyman on iOS for APP)
  • MyRailTime 2.0 Website (For checking station schedule only)

API Endpoints

  1. To retrieve full KTM Station List with Name and Code :

Send POST request to http://myrailtime.ktmb.com.my:8080/mobileApi/api/station/?isActive=true

with header :

Host: myrailtime.ktmb.com.my:8080
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

with content in JSON form :

{
  "clientId": "userMobile",
  "secretKey": "s3cr3t"
}

Response :

In JSON form

Make sure statusCode is 200 and there's data inside data under the JSON response.

  1. To retrieve specified station timetable / schedule

Send POST request to http://myrailtime.ktmb.com.my:8080/authApi/api/timetable/public?origin=$origincode&count=10000

where $origincode is the Station Code which can retrieved under the 1st API Endpoint

For example Kepong Sentral Code = 18400 and I wanted to retrieve Kepong Sentral's timetable / schedule :

The API Endpoint URL should look like this : http://myrailtime.ktmb.com.my:8080/authApi/api/timetable/public?origin=18400&count=10000

with header :

Host: myrailtime.ktmb.com.my:8080
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

with content in JSON form :

{
  "clientId": "userMobile",
  "secretKey": "s3cr3t"
}

Response :

In JSON form

Make sure statusCode is 200

If there's NO data inside data under the JSON response , which means there are currently no train for this station.

  1. To retrieve specified selected Origin - Destination timetable Send POST request to http://myrailtime.ktmb.com.my:8080/mobileApi/api/processor/journey?origin=$origincode&destination=$destinationcode&datetime=$time&limited=false

where

$origincode is the Origin Station Code which can retrieved under the 1st API Endpoint

$destinationcode is the Destination Station Code which can retrieved under the 1st API Endpoint

$time is 24 Hour format involving hour and minute only (Example : 0916 indicates 9:16AM)

For example : My Origin Station is Bandar Tasik Selatan (19600) and my Destination Station is KL Sentral (19100), and the time I'm proceed to check it is 11:15 AM (1115)

Your API Endpoint URL should be : http://myrailtime.ktmb.com.my:8080/mobileApi/api/processor/journey?origin=19600&destination=19100&datetime=1115&limited=false

with header :

Host: myrailtime.ktmb.com.my:8080
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148

with content in JSON form :

{
  "clientId": "userMobile",
  "secretKey": "s3cr3t"
}

Response :

In JSON form

Make sure statusCode is 200

If there's NO data inside data under the JSON response , which means there are currently no train serve from your Origin Station to Destination Station.

Proxied API Documentation

This project provide proxied MyRailTime2.0's API via PHP and return in JSON form.

  1. api/stationlist.php
  • Retrieve all Latest KTM's Station Name and Code in JSON form
  • No Query String required
  1. api/journey.php
  • Retrieve Train Information from provided Origin to Destination in JSON form
  • Query String required :

origincode - Origin KTM Station's Code

destinationcode - Destination KTM Station's Code

  1. api/stationschedule.php
  • Retrieve specified KTM Station's schedule and timetable in JSON form
  • Query String required :

stationcode - Specified KTM Station's Code

Issues

So far I have not yet encountered any Issue about this project , kindly create a Issue if you found anything that might affect the stability of this project.

I'm not very familar with PHP but I'll try my best to solve it.

Any Pull-Requests that make senses and able to improve this project is welcome!

Credits

  1. MyRailTime2.0
  2. KTMB

Screenshots

image image

image image

You might also like...
Guzzle, an extensible PHP HTTP client
Guzzle, an extensible PHP HTTP client

Guzzle, PHP HTTP client Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services. Simple interf

Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.

Httpful Httpful is a simple Http Client library for PHP 7.2+. There is an emphasis of readability, simplicity, and flexibility – basically provide the

PHP's lightweight HTTP client

Buzz - Scripted HTTP browser Buzz is a lightweight (1000 lines of code) PHP 7.1 library for issuing HTTP requests. The library includes three clients

HTTPlug, the HTTP client abstraction for PHP

HTTPlug HTTPlug, the HTTP client abstraction for PHP. Intro HTTP client standard built on PSR-7 HTTP messages. The HTTPlug client interface is compati

Requests for PHP is a humble HTTP request library. It simplifies how you interact with other sites and takes away all your worries.

Requests for PHP Requests is a HTTP library written in PHP, for human beings. It is roughly based on the API from the excellent Requests Python librar

Unirest in PHP: Simplified, lightweight HTTP client library.

Unirest for PHP Unirest is a set of lightweight HTTP libraries available in multiple languages, built and maintained by Mashape, who also maintain the

PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs
PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs

PHP Curl Class: HTTP requests made easy PHP Curl Class makes it easy to send HTTP requests and integrate with web APIs. Installation Requirements Quic

Simple handler system used to power clients and servers in PHP (this project is no longer used in Guzzle 6+)

RingPHP Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function. RingPHP be used to power HTTP clie

Owner
Sam Sam
Juz a normal person. Malaysian , Secondary School
Sam Sam
Free Cricket API - Live Cricket Score JSON API 🏏

Free Cricket API ?? Live Cricket Score API ?? unofficial API Data Fetched from Cricbuzz.com This is an unofficial API and not Linked or Partnered with

Santhosh Veer 60 Jan 2, 2023
PHP Curl ile letgo api kütüphanesi oluşturuldu. php ile letgo giriş yap.

Kendi LETGO API ile işlemler gerçekleştirelim. // email işlemleri $server = 'imap.gmail.com'; $user = '[email protected]'; $pass = 'password'; $port = 9

Görkem Bayraktar 2 Nov 3, 2022
PHP cURL for feed Instagram Graph API

php-curl-instagram-graph PHP cURL for feed Instagram Graph API Script made based on the new (2020) Instagram API that requires authorization token gen

null 12 Apr 13, 2022
A PHP HttpClient for the Neo4j ReST API with MultiDB Support

NeoClient This repository has moved Neoxygen's NeoClient has been moved to https://github.com/graphaware/neo4j-php-client Version 3 of this library is

Neoxygen 120 Oct 19, 2022
Transform your WordPress site into a modern GraphQL server: graphql-api.com.

GraphQL API for WordPress Transform your WordPress site into a modern GraphQL server: graphql-api.com. This plugin is the implementation for WordPress

GraphQL API 151 Dec 14, 2022
A YOURLS plugin allowing the shortening of multiple URLs with one API request.

Bulk URL Shortening - a YOURLS plugin Plugin for YOURLS Plugin URI: github.com/tdakanalis/bulk_api_bulkshortener Description: A YOURLS plugin allowing

Themistoklis Dakanalis 6 Aug 27, 2022
Creating an all in one AI with a web UI to control it. Create your own AI server and/or sell API keys to other people to use your AI.

+ Currently taking an hour or two break to spend some time with the wife. - Then going to work on auto refreshing the chat and document ingestion so y

null 10 Jun 14, 2023
Retrofit implementation in PHP. A REST client for PHP.

Retrofit PHP Retrofit is a type-safe REST client. It is blatantly stolen from square/retrofit and implemented in PHP. ❗ UPGRADE NOTICE ❗ Version 3 int

null 153 Dec 21, 2022
HTTP header kit for PHP 7.1+ (incl. PHP 8) based on PSR-7

HTTP header kit for PHP 7.1+ (incl. PHP 8) based on PSR-7 Installation composer require sunrise/http-header-kit How to use? HTTP Header Collection Mor

Sunrise // PHP 63 Dec 31, 2022
Express.php is a new HTTP - Server especially made for RESTful APIs written in PHP.

express.php Express.php is a new HTTP - Server especially made for RESTful APIs written in PHP. Features Fast The Library is handles requests fast and

null 5 Aug 19, 2022