-1

Please i have problem with php as when i want to login the session expire instantly , the Model :

public function Logger($login, $passe) {

    $login = addslashes($login);

    $passe = md5($passe);
        try {

            $conn = connexion::getConnexion();

            $conn->beginTransaction();

            $result = connexion::getConnexion()->query("SELECT id_user ,  type , login , nom , prenom , profil , enseignant, activer FROM p_user WHERE login = '$login' AND passe = '$passe' LIMIT 1");

            $data = $result->fetch(PDO::FETCH_ASSOC);

            $result->closeCursor();

            return $data;

        } catch (Exception $exc) {

            $conn->rollBack();

            return "Error :" . $exc->getMessage();

        }

    }

the controller :

if (isset($_POST)){
    $obj = new p_user(); 
    $result_connexion =$obj->Connecter($_POST['login'], $_POST['passe']); 
    if (empty($result_connexion)):
        die('Login Ou bien Mot de passe Non Correct');
    else:
    $_SESSION = $result_connexion;
   // var_dump($result_connexion);
    $p_profil = new p_profil(); 
    $get_liens=$p_profil->selectByTwoColumn('login', $result_connexion['login'], 'code_lien', 'LINK-0000068');

    if(!empty($get_liens))
    {
        die("Happy End");
    }

       die("Good");
    endif;

I'm trying to logging in but the page should redirect me to Dashboard but it's not it refresh to login page and i put code to print session login but it's null or empty

How to fix that and Thank you !!

Salem loress
  • 361
  • 1
  • 4
  • 13
  • You never call `session_start()` anywhere in this code. You can't have a session without `session_start()`. – Sherif Jan 24 '20 at 03:58
  • yess i know but it was in header_login model the issue was in page redirected after login model ! – Salem loress Jan 24 '20 at 04:24
  • You are not showing a lot of information in this code, we can see you instantiate an object but you are calling the method "Connecter" instead of "Logger". And I would suggest to avoid addslashes and use prepare statement instead : https://stackoverflow.com/a/26966401/6126481 – Jordan Daigle Jan 24 '20 at 05:07

1 Answers1

1

As per given code what I understand is, you have not call model function "Logger()"

Instead of this code

$result_connexion =$obj->Connector($_POST['login'], $_POST['passe']);

use below code:

$result_connexion =$obj->Logger($_POST['login'], $_POST['passe']);
ROOT
  • 10,813
  • 5
  • 29
  • 43
prathmesh
  • 26
  • 5