Check whether the user have logged
Posted: Sun Mar 28, 2004 11:48 pm
Hi,
Anyone know how to check whether the user have logged before they can enter into the page?
I have tried this codes but cannot work and i not sure correct anot. Can anyone pls help me?urgent!!!
loginAction.php
<?php
$user_id = $_POST['user_id'];
$password = $_POST['password'];
$db = mysql_connect("localhost", "", "");
mysql_select_db("Admin",$db);
//$query = "select Password from Admin where Username='$username'";
$query = "SELECT * FROM Admin WHERE user_id = '" . $user_id . "' AND password = '" . $password . "'";
$result = mysql_query($query, $db) or die('error making query');
if(!$row = mysql_fetch_assoc($result)){
echo '<font size = 4><br><center>Sorry. <br> Please try again.</center></font>';
} else {
header('Location: admin.php');
session_start();
session_register("sign");
session_register("user_id");
session_register("admin_level");
exit;
}
?>
deleteUser.php
<?
session_start();
$user_id = $_SESSION["user_id"];
$admin_level = $_SESSION["admin_level"];
$signin = $_SESSION["sign"];
if (!$signin)
{
header('Location: index.php');
}
else
{
header('Location: deleteUser.php');
}
?>
Thank You Very Much!
Anyone know how to check whether the user have logged before they can enter into the page?
I have tried this codes but cannot work and i not sure correct anot. Can anyone pls help me?urgent!!!
loginAction.php
<?php
$user_id = $_POST['user_id'];
$password = $_POST['password'];
$db = mysql_connect("localhost", "", "");
mysql_select_db("Admin",$db);
//$query = "select Password from Admin where Username='$username'";
$query = "SELECT * FROM Admin WHERE user_id = '" . $user_id . "' AND password = '" . $password . "'";
$result = mysql_query($query, $db) or die('error making query');
if(!$row = mysql_fetch_assoc($result)){
echo '<font size = 4><br><center>Sorry. <br> Please try again.</center></font>';
} else {
header('Location: admin.php');
session_start();
session_register("sign");
session_register("user_id");
session_register("admin_level");
exit;
}
?>
deleteUser.php
<?
session_start();
$user_id = $_SESSION["user_id"];
$admin_level = $_SESSION["admin_level"];
$signin = $_SESSION["sign"];
if (!$signin)
{
header('Location: index.php');
}
else
{
header('Location: deleteUser.php');
}
?>
Thank You Very Much!