Realtime HTML/REACTJS + PHP authentication
This example shows how to authenticate a Realtime security token based on a user successful login. The backend is coded in PHP and the client website uses React.
The login is mocked for demo purposes with the following credentials:
- username: demo
- password: demo
- The user enters the login credentials
- An AJAX POST request is sent to the PHP backend passing the user credentials for validation
- The PHP backend verifies the credentials and if they are valid authenticates a Realtime token with the appropriate channel permissions
- The authenticated token (or error) is returned in the response body of the AJAX request
- The login page saves the token in the browser local storage and redirects the user to the chat page
- The chat page connects to Realtime using the authenticated token saved in the local storage
Running this example
Copy the code to your local PHP server and open the following URL in your browser (don't forget to enter your Realtime credentials where required in the code):
About the Realtime Framework
Part of the The Realtime® Framework, Realtime Cloud Messaging (aka ORTC) is a secure, fast and highly scalable cloud-hosted Pub/Sub real-time message broker for web and mobile apps.
If your application has data that needs to be updated in the user’s interface as it changes (e.g. real-time stock quotes or ever changing social news feed) Realtime Cloud Messaging is the reliable, easy, unbelievably fast, “works everywhere” solution.
PHP SDK Reference