As I develop a new app, I am aiming to separate the HTML/JS layer from the PHP layer in order to prepare for a potential phonegap version in the future.
One major concern I have is regarding authentication. Since I won't be able to rely on session variables this time, I need to come up with a different approach to handle authentication. Here's my plan:
- The user will input their login information and submit it via ajax to a PHP file.
- The PHP file will validate the login credentials and generate a key-token for that user. This token will be stored on the user's end (e.g. in MySQL) and sent back to the client side as JavaScript.
- The browser will receive the key-token and store it in session_storage.
- Each subsequent ajax request will include this token, which will then be verified by the PHP script.
Do you see any potential flaws in this plan? Is there a simpler or more effective solution available? My idea is loosely based on how PHP sessions work, but using a key-token instead of a session ID. Any advice would be greatly appreciated.