php版本从5.3升级到5.4.x,这会在登录验证中产生问题

php版本从5.3升级到5.4.x,这会在登录验证中产生问题,php,validation,login,Php,Validation,Login,这个密码给了我 致命错误:php版本升级后调用未定义函数session_register(),请任何人帮我解决这个问题 $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name // Con

这个密码给了我 致命错误:php版本升级后调用未定义函数session_register(),请任何人帮我解决这个问题
    $host="localhost"; // Host name 
    $username=""; // Mysql username 
    $password=""; // Mysql password 
    $db_name=""; // Database name 
    $tbl_name=""; // Table name 

    // Connect to server and select databse.
    mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");

    // username and password sent from form 
    $myusername=$_POST['myusername']; 
    $mypassword=$_POST['mypassword']; 

    // To protect MySQL injection (more detail about MySQL injection)
    $myusername = stripslashes($myusername);
    $mypassword = stripslashes($mypassword);
    $myusername = mysql_real_escape_string($myusername);
    $mypassword = mysql_real_escape_string($mypassword);
    $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
    $result=mysql_query($sql);

    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);

    // If result matched $myusername and $mypassword, table row must be 1 row
    if($count==1){

        // Register $myusername, $mypassword and redirect to file "login_success.php"
        session_register("myusername");
    session_register("mypassword"); 
        header("location:operator.php");
        }
        else {
        header("location: http://");

        }
        ?>
此代码适用于每个目标页operator.php致命错误:调用未定义的函数session_register()


而不是
会话\u寄存器

尝试使用
$\u会话

会话U寄存器已折旧: 更改:

session_register("myusername");
致:


与其他所有调用类似。

此函数在5.3.0中被弃用,在5.4.0中被删除。不要用它。直接分配
$\u会话
变量。脚本中有许多需要改进的地方。首先,不要使用mysql函数,也不要保存明文密码——你要对你的用户负责。应该为mysql连接设置编码
mysql\u set\u字符集('utf8')
,应在查询中设置
限制1
,并实施真正的验证过程,而不是计算结果。我是此plz的新手,如果您无法将我重定向到主登录,请给我演示:(这与
session\u register
无关,这是您的查询问题。我已按您所说进行了更改,但不起作用。它将我重定向到主登录$\u session[“myusername”]=$myusername;这与此无关。该重定向来自
if($count==1)
失败。@user3532635您所需要的就是使用此处的提示并进行调试,直到它无法看到失败的原因。如果您不理解自己的代码,您将无法理解“演示”。时间就是金钱伙伴:)
session_register("myusername");
$_SESSION["myusername"] = $myusername;