Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

352
Visualizações
Android and PHP: Check which user or users are currently logged in

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

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

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.

over 4 years ago · Santiago Trujillo Relatório

0

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";
    }

?>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda