我确定一切都是正确的。一直在打破我的脖子。
这是index.php。我只是包含文件并调用函数 来自functions.php
我根本不知道发生了什么。 这是一个正确的写作
<?php
if(basename($_SERVER['SCRIPT_FILENAME']) == basename(__FILE__)) die("Access denied");
ob_start();
require_once 'includes/app/config.php';
require_once 'includes/app/init.php';
if (!(empty($maintaince))) {
header('Location: maintenance.php');
exit;
}
if (!($user -> LoggedIn()) || !($user -> notBanned($odb))){
header('location: relogin.php');
die();
}
?>
这是functions.php
<?php
class user {
function realIP(){
switch(true){
case (!empty($_SERVER['HTTP_X_REAL_IP'])) : return $_SERVER['HTTP_X_REAL_IP'];
case (!empty($_SERVER['HTTP_CLIENT_IP'])) : return $_SERVER['HTTP_CLIENT_IP'];
case (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) : return $_SERVER['HTTP_X_FORWARDED_FOR'];
default : return $_SERVER['REMOTE_ADDR'];
}
}
//Kijkt of de gebruiker zijn account geblockeerd is
function isBanned($odb){
$SQL = $odb -> prepare("SELECT `status` FROM `users` WHERE `ID` = ?");
$SQL -> execute(array($_SESSION['ID']));
$status = $SQL -> fetchColumn(0);
if ($status == 0){
return true;
} else {
//Blockeert de gebruiker, En logt hem uit
session_destroy();
return false;
}
}
//Kijkt of de gebruiker admin is
function isadmin(){
$SQL = $odb -> prepare("SELECT `rank` FROM `users` WHERE `ID` = ?");
$SQL -> execute(array($_SESSION['ID']));
$rank = $SQL -> fetchColumn(0);
if ($rank == 0){
return true;
} else {
return false;
}
}
//de login functie (bewaart cookies en http header data door middel van @session_start(); )
function LoggedIN(){
@session_start();
if (isset($_SESSION['username'], $_SESSION['ID'])){
return true;
} else {
return false;
}
}
}
?>
答案 0 :(得分:0)
您必须将方法LoggedIN()放在用户类中。
当我看到你把你的方法放在外面时,它可以像经典函数一样在课外调用。