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
- PHP 7.4 and above
- Redis and Redis PHP Extension installed (For Rate Limit purposes)
- 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)
- Nginx / Apache / Any web server with PHP configured install and running
Deployment
- Download the source code and extract to the designated folder on ur web server root folder.
- Make sure Redis and Redis PHP Extension installed.
- Make sure PHP is preconfigured with your web server.
- 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
- 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.
- 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.
- 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.
api/stationlist.php
- Retrieve all Latest KTM's Station Name and Code in JSON form
- No Query String required
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
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
- MyRailTime2.0
- KTMB