if (session_status() == PHP_SESSION_NONE) { session_start(); } header("Cache-Control: no-cache"); header("Pragma: no-cache"); include('con_db.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['rememberme'])) { setcookie("email", $_POST['usernameinput'], time() + 3600, "/", "", 0); } $postemail = $_POST['usernameinput']; $postpassword = mysqli_real_escape_string($con, $_POST['passwordinput']); $loginfailed = 1; ////////////////////////////////////////////////// $useremailid = 1; $a = $postemail; if (strpos($a, '@') !== false) { } else { $useremailid = 0; } ////////////////////////////////////////////////// /// EMAIL ID IS CHECKING INT HE USERS TABLE if ($useremailid == 1) { $result = mysqli_query($con, "SELECT * FROM users WHERE email ='$postemail' AND password='$postpassword'"); while ($row = mysqli_fetch_array($result)) { $loginfailed = 0; $loggedin = 1; $id = $row['id']; $userid = $row['id']; $name = $row['name']; $password = $row['password']; $email = $row['email']; $schoolid = $row['schoolcode']; $_SESSION["userloggingin"] = 1; $_SESSION["email"] = $email; $_SESSION["emailsession"] = $email; $_SESSION["userid"] = $id; $_SESSION["schoolid"] = $schoolid; $role = $row['role']; $_SESSION["userrole"] = $role; $category = $row['category']; $_SESSION["category"] = $category; if ($row['status'] == 1) { $tobeactivated = 0; $_SESSION["tobeactivated"] = 0; } else { $tobeactivated = 1; $_SESSION["tobeactivated"] = 1; } if ($row['code'] != '') { $_SESSION["codetobeactivated"] = 0; } else { $codetobeactivated = 1; $_SESSION["codetobeactivated"] = 1; } //query while closed // header('Location: index.php'); $array = array(); $resultx = mysqli_query($con, "SELECT * FROM useraccess WHERE userid ='$id'"); while ($row = mysqli_fetch_array($resultx)) { $array[] = $row; } $_SESSION["useraccessrole"] = $array; } } else { $result = mysqli_query($con, "SELECT * FROM users WHERE email ='$postemail' AND password='$postpassword'"); while ($row = mysqli_fetch_array($result)) { $loginfailed = 0; $loggedin = 1; $id = $row['id']; $userid = $row['id']; $name = $row['name']; $password = $row['password']; $email = $row['email']; $schoolid = $row['schoolcode']; $_SESSION["userloggingin"] = 1; $_SESSION["email"] = $email; $_SESSION["emailsession"] = $email; $_SESSION["userid"] = $id; $_SESSION["schoolid"] = $schoolid; $role = $row['role']; $_SESSION["userrole"] = $role; $category = $row['category']; $_SESSION["category"] = $category; if ($row['status'] == 1) { $tobeactivated = 0; $_SESSION["tobeactivated"] = 0; } else { $tobeactivated = 1; $_SESSION["tobeactivated"] = 1; } if ($row['code'] != '') { $_SESSION["codetobeactivated"] = 0; } else { $codetobeactivated = 1; $_SESSION["codetobeactivated"] = 1; } //query while closed // header('Location: index.php'); $array = array(); $resultx = mysqli_query($con, "SELECT * FROM useraccess WHERE userid ='$id'"); while ($row = mysqli_fetch_array($resultx)) { $array[] = $row; } $_SESSION["useraccessrole"] = $array; } //admissionnum was used instead of userid $result = mysqli_query($con, "SELECT * FROM students WHERE userid ='$postemail' AND password='$postpassword'"); while ($row = mysqli_fetch_array($result)) { $loginfailed = 0; $loggedin = 1; $id = $row['id']; $userid = $row['userid']; $admissionnum = $row['admissionnum']; $name = $row['name']; $password = $row['password']; $email = $row['name']; $schoolid = $row['schoolid']; $_SESSION["userloggingin"] = 1; $_SESSION["email"] = $email; $_SESSION["emailsession"] = $email; $_SESSION["userid"] = $id; $_SESSION["admissionnum"] = $admissionnum; $_SESSION["schoolid"] = $schoolid; //$role=$row['role']; $role = 100; $_SESSION["userrole"] = $role; //$role; //$category=$row['category']; //$_SESSION["category"]=$category; if ($row['status'] == 1) { $tobeactivated = 0; $_SESSION["tobeactivated"] = 0; } else { // $tobeactivated=1; // $_SESSION["tobeactivated"]=1; } if ($row['code'] != '') { //$_SESSION["codetobeactivated"]=0; } else { //$codetobeactivated=1; //$_SESSION["codetobeactivated"]=1; } //query while closed // header('Location: index.php'); /* $array = array(); $resultx = mysqli_query($con, "SELECT * FROM useraccess WHERE userid ='$id'"); while($row = mysqli_fetch_array($resultx)) { $array[] = $row; } $_SESSION["useraccessrole"]=$array; */ } } } if (isset($_POST['api'])) { session_start(); $api = $_POST['api']; $_SESSION['api'] = $api; } if (isset($_GET['api'])) { session_start(); $api = $_GET['api']; $_SESSION['api'] = $api; } ?>