我希望生病得到一些幫助。當我試圖登錄該系統即時通訊會話註冊時出現錯誤: *致命錯誤:調用未定義的函數session_register()在C:\ xampp \ htdocs \ check.php在第18行* btw我只是開始學習PHP的,所以我是一個新手在那裏:)PHP會話註冊錯誤
有一個代碼Register.php:
<?php
include('MySQL.php');
include('password.php');
$Username = $_POST['user'];
$Password = $_POST['password'];
$Re_Password = $_POST['password2'];
if($Username == "")
{
die("You don't enter a username!");
}
if($Password == "" || $Re_Password == "")
{
die("You didn't enter one of your passwords!");
}
if($Password != $Re_Password)
{
die("Your passwords don't match! Try again.");
}
$query = mysql_query("SELECT * FROM users WHERE username='$Username'");
if(mysql_num_rows($query) != 0)
{
echo "Username already exists";
}
else
{
$hash = password_hash($Password, PASSWORD_BCRYPT);
if (password_verify($Password, $hash)) {
if(!mysql_query("INSERT INTO users (username, password)
VALUES ('$Username', '$hash')"))
{
die("Connection problems!");
}
echo "<center>";
echo "Registration was successfull!<br>";
echo "Your user name: $Username<br>";
echo "<a href='login.php'>Login to the system</a>";
echo "</center>";
}
}
?>
Check.php:
<?php
ob_start();
include('MySQL.php');
$username=$_POST['user'];
$password=$_POST['password'];
$query = mysql_query ("SELECT * FROM users WHERE username='$username' AND password='$password'");
if(mysql_num_rows($query) == 1)
{
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("username");
session_register("password");
header("location:success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
有什麼建議嗎? – David 2013-04-25 08:44:46
直接使用$ _SESSION ['username'] = $ username; – 2013-04-25 08:45:05