简体   繁体   English

PHP检查登录验证

[英]PHP check login verification

I have looked for a while to find how to fix this issue with deprecated PHP session_register and session_is_registered() functions. 我寻找了一段时间,以查找如何使用不赞成使用的PHP session_register和session_is_registered()函数解决此问题。 Here is my code i'm currently using 这是我目前正在使用的代码

// 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 "home.php"
session_start();
$_SESSION['myusername'] = $myusername;
$_SESSION['mypassword'] = $mypassword;
//session_register("myusername");
//session_register("mypassword");
header("location:home.php");
}

Not sure if I include both of these variable or just keep my username as the main verification? 不确定我是否同时包含这两个变量,还是只是保留我的用户名作为主要验证?

$_SESSION['myusername'] = $myusername;

$_SESSION['mypassword'] = $mypassword;

As for my main page after login. 至于我登录后的主页。 I have no idea what to put in here as in what code to use for my case. 我不知道在这里输入什么内容,以及在我的案例中使用什么代码。

<?
session_start();
if(empty($_SESSION["myusername"])){
header("location:index.php");
exit();
}
?>

My site is 我的网站是

http://pyrostudio.byethost16.com/index.php and i created account info so people can access. http://pyrostudio.byethost16.com/index.php ,我创建了帐户信息,以便人们可以访问。 User is "ffffff" without "" and pass is "ffffff" without"" in fact that i don't think the session is even registering. 用户实际上是不带“”的“ ffffff”,而通行证是不带“”的“ ffffff”,事实上,我认为会话甚至都没有注册。 here is the home page after login. 这是登录后的主页。

http://pyrostudio.byethost16.com/home.php http://pyrostudio.byethost16.com/home.php

ignore the other errors this is to show that the session dosent even register. 忽略其他错误,这是为了表明会话剂量均匀注册。 though i do appologize for a long question. 虽然我很抱歉很长的问题。 I have not idea what to do when 5.4 came around. 我不知道5.4出现时该怎么办。

You can use 您可以使用

<?
session_start();
if(!empty($_SESSION["myusername"]) && isset($_SESSION["myusername"])  ){
//do something
}else{
header("location:index.php");
exit();
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM