无法限制对 php5 页面的访问

发布于 2024-11-18 23:03:35 字数 2148 浏览 3 评论 0原文

我有 2 个页面:admin.php 和 admin_index.php。我在 admin.php 中有一个用户名和密码字段,我使用数据库对其进行身份验证。如果用户通过身份验证,则会加载 admin_index.php。我使用 Dreamweaver cs5 将限制访问页面服务器行为添加到 admin_index.php 页面。但如果我尝试使用 url 直接访问 admin_index.php 页面,我仍然可以。这两个页面的会话代码都位于所有其他内容之上,它是:

<?php 
if (!isset($_SESSION)) {
session_name("ckfinder");   
session_start();
$_SESSION['site'] = "wildgameservices"; 
} 
?>

任何人都可以指出我的错误吗?

编辑:我每次测试页面之前都清除了cookie。

编辑:由 Dreamweaver 添加的用于身份验证的自定义代码:

<?php
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
// For security, start by assuming the visitor is NOT authorized. 
$isValid = False; 

// When a visitor has logged into this site, the Session variable MM_Username set      
equal to their username. 
// Therefore, we know that a user is NOT logged in if that Session variable is blank. 
if (!empty($UserName)) { 
// Besides being logged in, you may restrict access to only certain users based on an 
ID established when they login. 
// Parse the strings into arrays. 
$arrUsers = Explode(",", $strUsers); 
$arrGroups = Explode(",", $strGroups); 
if (in_array($UserName, $arrUsers)) { 
  $isValid = true; 
} 
// Or, you may restrict access to only certain users based on their username. 
if (in_array($UserGroup, $arrGroups)) { 
  $isValid = true; 
} 
if (($strUsers == "") && true) { 
  $isValid = true; 
} 
} 
return $isValid; 
}

$MM_restrictGoTo = "admin.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers,     

$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" .    

urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo); 
exit;
}

I have 2 pages: admin.php and admin_index.php. I have a username and password field in admin.php, which I authenticate using a database. If the user is authenticated, the admin_index.php loads. I added the restrict access page server behaviour to admin_index.php page using dreamweaver cs5. But if I try to directly access the admin_index.php page using the url, I am still able to. The session code for both the pages is right on top of all other stuff and it is:

<?php 
if (!isset($_SESSION)) {
session_name("ckfinder");   
session_start();
$_SESSION['site'] = "wildgameservices"; 
} 
?>

Can anyone please point out my mistake?

edit: I have cleared cookies before I test the page each time.

edit: custom code added by dreamweaver for authentication:

<?php
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
// For security, start by assuming the visitor is NOT authorized. 
$isValid = False; 

// When a visitor has logged into this site, the Session variable MM_Username set      
equal to their username. 
// Therefore, we know that a user is NOT logged in if that Session variable is blank. 
if (!empty($UserName)) { 
// Besides being logged in, you may restrict access to only certain users based on an 
ID established when they login. 
// Parse the strings into arrays. 
$arrUsers = Explode(",", $strUsers); 
$arrGroups = Explode(",", $strGroups); 
if (in_array($UserName, $arrUsers)) { 
  $isValid = true; 
} 
// Or, you may restrict access to only certain users based on their username. 
if (in_array($UserGroup, $arrGroups)) { 
  $isValid = true; 
} 
if (($strUsers == "") && true) { 
  $isValid = true; 
} 
} 
return $isValid; 
}

$MM_restrictGoTo = "admin.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers,     

$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0) 
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" .    

urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo); 
exit;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别念他 2024-11-25 23:03:35

您不需要执行 if 语句并检查有效会话吗?也许是这样的

if($_SESSION['site'] != "wildgameservices"){
  return;
  // or exit(); not sure what you want
}

Don't you need to do an if statement and check for valid session? Something like this maybe

if($_SESSION['site'] != "wildgameservices"){
  return;
  // or exit(); not sure what you want
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文