I am new to PHP guys, so this is my problem
index.php
if(!function_exists("session_register")) {
function session_register() {
$args = func_get_args();
if(count($args) <= 0)
return;
foreach($args as $key)
$_SESSION[$key] = $GLOBALS[$key];
}
}
include("connection2.php");
ob_start();
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$myusername = mysqli_real_escape_string($db,$_POST['username']);
$mypassword = mysqli_real_escape_string($db,$_POST['pass']);
$sql = "SELECT * FROM Users WHERE UserName='$myusername' and UserPassword='$mypassword'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result);
$userID = $row["UserID"];
$userType = $row["UserType"];
$count = mysqli_num_rows($result);
if($count >0 ) {
if($userType == 2 || $userType == 1 ) {
$_SESSION['UserID']=$userID;
$_SESSION['UserType']=$userType;
header("location: dashboard.php");
ob_end_flush();
} else {
header("location:index.php");
ob_end_flush();
}
}
}
session.php
<?php
include('connection2.php');
session_start();
$userID = $_SESSION['UserID'];
$userType = $_SESSION['UserType'];
$ses_sql = mysqli_query($db,"select * from Users where UserID = $userid ");
$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$user_info = $row['UserInfo'];
if(!isset($_SESSION['UserID'])){
header("location:index.php");
die();
}
?>
dashboard.php
<?php
include("session.php");
if($userType == 1){
include("_header.php");
}else {
include("_header2.php");
}
?>
my code always redirects to index.php but i can see my variables /* $userID = $row["UserID"]; / and / $userType = $row["UserType"];*/ in index.php
how can I pass my variables on dashboard.php with or without using session.
I need help. thank you very much.