[英]Prevent php direct page access in the url bar
我正在核心php中做一个小应用程序,这里我的登录数据库是这样的
id
firstname
lastname
email
userid
account_type
contactno
password
在登录文件中的代码是这样的
<?php
include_once("include/connection.php");
session_start();
session_unset();
?>
<?php
$msg="";
if(isset($_REQUEST['sub'])){
$pswd=sha1($_REQUEST['psd']);
$sel=mysql_query("select * from login where userid='".$_REQUEST['uid']."' and password='".$pswd."'");
$rowsel=mysql_num_rows($sel);
if($rowsel==1){
$selacc=mysql_fetch_array($sel);
if($selacc['status']!='banned'){
$_SESSION['uid']=$selacc['userid'];
$_SESSION['uname']=$selacc['fname']." ".$selacc['lname'];
$_SESSION['upassword']=$selacc['password'];
$_SESSION['acctype']=$selacc['acctype'];
$_SESSION['agentcode']=$selacc['agent_code'];
$_SESSION['authentication']="authenticated";
header("location:dashboard.php");
}
}
else{
$msg="Enter Valid Username Password";
}
}
?>
<body>
<form name="login-form" method="post" action="#">
<input type="text" name="uid" class="inputbox" />
<input type="password" name="psd" class="inputbox" />
<input type="submit" name="sub" value="" class="inputbotton" />
</form>
现在,登录后将定向用户到dashboard
。 但是从这里当我直接输入``一个页面名称(让我们说posts.php)时,它将被重定向到post.php文件。 但是在这里,我希望有人拒绝访问,即当有人将直接在url中输入页面名称(例如post.php)时,它应该显示一些错误。 但是当页面是正常重定向时,它应该显示该页面。我想防止在地址栏中的直接页面访问,但是当页面是正常重定向时,它应该显示该页面。
例如,只需检查上一页中设置的任何会话变量
if(!isset($_SESSION['uid'])){
echo 'error';
exit;
}
在顶部做
其中有两个因素。
1)您在服务器上的文件夹和文件权限。
2)首次登录时,应显示登录页面。 但是当你再次做同样的事情时。 变量将存储在会话中,直到您关闭浏览器。 因此,关闭浏览器,然后重试。 您需要检查是否设置了会话ID,并据此做出决定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.