我有这个函数文件。通过这样做... <?php include('functions.php'); ?>
...我是在其中运行所有函数,还是只是允许调用它们(使它们存在于当前范围内)。
抱歉,如果这是一个基本问题,我是 PHP 新手!
<?php
/*
* -------------------------------------------------------------------------------------
* ---------------------------- GLOBALLY AVAILABLE FUNCTIONS ---------------------------
* -------------------------------------------------------------------------------------
*/
function user_loggedin_check() {
if(isset($_COOKIE['logged_in']) && ($_COOKIE['logged_in'] == true)){
$logged_in = true;
setcookie("logged_in", $logged_in, time()+14400);
return true;
} else {
header('Location: index.php?loginerr=6');
exit();
}
}
function permission_level_2_check() {
if(isset($_COOKIE['permission_level']) && ($_COOKIE['permission_level'] == 2)){
$logged_in = true;
setcookie("logged_in", $logged_in, time()+14400);
return true;
} else {
setcookie("logged_in", false, time()-1);
setcookie("permission_level", 1, time()-1);
session_unset();
session_destroy();
header('Location: index.php?loginerr=7');
exit();
}
}
function permission_level_3_check() {
if(isset($_COOKIE['permission_level']) && ($_COOKIE['permission_level'] == 3)){
$logged_in = true;
setcookie("logged_in", $logged_in, time()+14400);
return true;
} else {
setcookie("logged_in", false, time()-1);
setcookie("permission_level", 1, time()-1);
session_unset();
session_destroy();
header('Location: index.php?loginerr=7');
exit();
}
}
function display_login_errors() {
/*
* -------------------------------------------------------------------------------------
* ---------------------------------- ERROR LIST ---------------------------------------
* -------------------------------------------------------------------------------------
*/
/*
* loginerr=0 -> passwords don't match
* loginerr=1 -> username already exists in DB
* loginerr=2 -> registration is currently disabled
* loginerr=3 -> password is too long and/or too short
* loginerr=4 -> email isn't in proper format
* loginerr=5 -> email is too long and/or too short
* loginerr=6 -> user isn't logged in, generic redirect to login page error
* loginerr=7 -> user doesn't have the required access to view that page
*/
if(isset($_GET["loginerr"])){
$loginerr = $_GET["loginerr"];
switch ($loginerr) {
case 0:
echo "<div class='alert alert-error pagination-centered frontpage-alert'>";
echo "<strong>Your passwords didn't match. Try again.</strong>";
echo "</div>";
break;
case 1:
echo "<div class='alert alert-error pagination-centered frontpage-alert'>";
echo "<strong>That email address is already registered.</strong>";
echo "</div>";
break;
case 2:
echo "<div class='alert alert-error pagination-centered frontpage-alert'>";
echo "<strong>Registration is currently disabled. Try again later.</strong>";
echo "</div>";
break;
case 3:
echo "<div class='alert alert-error pagination-centered frontpage-alert'>";
echo "<strong>Your password must be between 4 and 32 characters in length.</strong>";
echo "</div>";
break;
case 4:
echo "<div class='alert alert-error pagination-centered frontpage-alert'>";
echo "<strong>Your email address didn't match proper formatting (email@domain.com).</strong>";
echo "</div>";
break;
case 5:
echo "<div class='alert alert-error pagination-centered frontpage-alert'>";
echo "<strong>Your email address must be between 6 and 32 characters in length.</strong>";
echo "</div>";
break;
case 6:
echo "<div class='alert alert-error pagination-centered'>";
echo "<strong>You need to be logged in to access that page. Please log in.</strong>";
echo "</div>";
break;
case 7:
echo "<div class='alert alert-error pagination-centered'>";
echo "<strong>You don't have access to view that page. You have been logged out due to suspicious activity.</strong>";
echo "</div>";
break;
}
}
}
?>