0

after refresh page its logout from system

this code for session:

<?php

if(!isset($_SESSION['username'])){
    echo "<script>window.location.href='login.php'</script>";

    exit;
    }

$check_session=$db->countRecords("select * from user_sessions where username='".$_SESSION["username"]."' and session_id='".$_SESSION["session_id"]."'");


if($check_session<=0)
    {

        session_start();
        session_destroy();
    echo "<script>window.location.href='login.php'</script>";

    }

    $last_month=date("Y-m-1",strtotime("-1 Months")); 


    $delete_session=$db->Delete_Record("admin_sessions"," session_date<='".$last_month."'");
?>
Pupil
  • 23,834
  • 6
  • 44
  • 66
  • window.location.href='login.php'"; exit; } $check_session=$db->countRecords("select * from user_sessions where username='".$_SESSION["username"]."' and session_id='".$_SESSION["session_id"]."'"); if($check_session<=0) { session_start(); session_destroy(); echo ""; } $last_month=date("Y-m-1",strtotime("-1 Months")); $delete_session=$db->Delete_Record("admin_sessions"," session_date<='".$last_month."'"); ?> – סטודיו פרץ May 07 '19 at 09:52
  • 1
    `session_start();` has to go to the most top of your file – B001ᛦ May 07 '19 at 09:54
  • Possible duplicate of [Session variables not working php](https://stackoverflow.com/questions/19692157/session-variables-not-working-php) – Masoud Keshavarz May 07 '19 at 11:38

0 Answers0