I am currently working on a mobile application. I have created an online database and am able to establish connection to it with the app. The user can register and log in to this app, and this part of the app works perfectly. Also in this app, I allow users to book for classes, the problem I am running into is linking the classes information table with the user information table. I need to know the "user id" of the current logged on user so I can add this ID to the classes table.
Whats the easiest way to do that? I have read that Sessions would be helpful but i do not know how to start implementing it in my code. Any help would greatly be appreciated.
Side Note:
I used PHP files to login and register users, as well as establishing the connection. These files were uploaded to my online server, which the application can connect to and call the appropriate file according to the function. For example, when logging in, the app will call the login.php
you have to add a field in your user table, a bit, if it is turned on means if that bit is equal to 1 it means user is already login and if that bit is 0 then user is not already login, you can use Shared Preferences to check for the same app in which user is logged in.
If user password is right then you should do the following in your php compare if password and user input are == to the stored in db then if are true
<?php
if(session_id() == '') {
session_start();
}
if($user == $db_user) && ($password == $db_password)){
$_SESSION["login"] = "1";
} else {
$_SESSION["login"] = "0";
}
?>
php file to protect page to not be seen by others
<?php
if(session_id() == '') {
session_start();
}
if(isset($_SESSION["login"] == 1))){
echo "user logged";
} else {
echo "invlaid user or password";
}
?>