-1
這是我的登錄表單php代碼。據我所知,這段代碼沒問題,但會話處理存在問題。我認爲在我的代碼中沒有會話創建。但無法看到任何錯誤當然我研究了許多資源,證明了這一點。必須讚賞任何幫助。php登錄會話處理問題
主頁 -
<?php
session_start();
session_regenerate_id();
if(!isset($_SESSION['user'])) // if there is no valid session
{
header("Location: login.html?action=no");
die();
} else {
}
?>
登錄頁面(的index.php) -
<?php
if(isset($_POST['submit']))
{
$dbHost = "localhost"; //Location Of Database usually its localhost
$dbUser = "root"; //Database User Name
$dbPass = ""; //Database Password
$dbDatabase = "testdb"; //Database Name
$db = mysql_connect($dbHost,$dbUser,$dbPass)or die("Error connecting to database.");
//Connect to the databasse
mysql_select_db($dbDatabase, $db)or die("Couldn't select the database.");
//Selects the database
/*
The Above code can be in a different file, then you can place include'filename.php'; instead.
*/
//Lets search the databse for the user name and password
//Choose some sort of password encryption, I choose sha256
//Password function (Not In all versions of MySQL).
$usr = mysql_real_escape_string($_POST['username']);
$pas = hash('sha256', mysql_real_escape_string($_POST['password']));
$sql = mysql_query("SELECT * FROM users_table
WHERE username='$usr' AND
password='$pas'
LIMIT 1");
session_start();
if(isset($_POST['username']) && isset($_POST['password']))
{
if(auth($_POST['username'], $_POST['password']))
{
// auth okay, setup session
$_SESSION['user'] == $_POST['username'];
isset($_SESSION['user']);
session_register("user");
// redirect to required page
$Groups = $result["Groups"];
if($Group == 'a')
{ // "Admin"
$_SESSION['user'] == $_POST['username'];
isset($_SESSION['user']);
session_register("user");
header("Location: video.html");
} elseif($Group == 'admin') {
$_SESSION['user'] == $_POST['username'];
isset($_SESSION['user']);
session_register("user");
header("Location: home.html");
} else {
// didn't auth go back to loginform
header("Location: index.html");
}
}
}
?>
我downvote這個問題,因爲你沒有啓用error_reporting,並嘗試自己解決這些簡單的語法錯誤。真的很懶惰。 – DanFromGermany