Php 致命错误:调用未定义的函数isLoggedIn()
我不断收到错误“致命错误:在第2行的/home/********/public_html/login.php中调用未定义的函数isLoggedIn()” index.phpPhp 致命错误:调用未定义的函数isLoggedIn(),php,Php,我不断收到错误“致命错误:在第2行的/home/********/public_html/login.php中调用未定义的函数isLoggedIn()” index.php <?php $page = "Home"; require_once "header.php"; //content global $prostats; ?> //Some html stuff <?php require_once "footer.php"; ?> //
<?php
$page = "Home";
require_once "header.php";
//content
global $prostats;
?>
//Some html stuff
<?php
require_once "footer.php";
?>
//一些html内容
login.php
<?php
if (!isLoggedIn())
{
// user is not logged in.
if (isset($_POST['cmdlogin']))
{
// retrieve the username and password sent from login form & check the login.
if (checkLogin($_POST['username'], $_POST['password']))
{
echo '<ul class="pull-right"><li>';
show_userbox ();
echo '</li></ul>';
}
else
{
echo '<ul class="pull-right">
<li class="signUp"><a href="http://elitekastdev.com/register.php">Sign Up</a></li>';
echo '<li class="logIn"><a>Log In</a><p>Incorrect Login information</p><ul><li>';
show_loginform ();
echo '</li></ul></li></ul>';
}
}
else
{
// User is not logged in and has not pressed the login button
// so we show him the loginform
echo '<ul class="pull-right">
<li class="signUp"><a href="http://elitekastdev.com/register.php">Sign Up</a></li>';
echo '<li class="logIn"><a>Log In</a><ul><li>';
show_loginform ();
echo '</li></ul></li></ul>';
}
}
else
{
// The user is already loggedin, so we show the userbox.
echo '<ul class="pull-right"><li>';
show_userbox ();
echo '</li></ul>';
}
?>
如果在php.ini文件中没有启用URL包含包装器,包含URL将导致致命错误。请参阅:)
假设login.php实际上与其他脚本位于同一服务器上,则应使用正确的本地路径将其包括在内,并且不使用HTTP URL使用绝对或相对路径;PHP还将使用PHP.ini配置中配置的任何路径
更多信息:
当您有意像在代码中那样包含HTTP URL时:
include "http://example.com/login.php";
您通常无法访问login.php文件中的函数,因为该文件将首先在目标服务器上处理,您将包含来自该脚本的“输出”。您不应该使用包含“login.php”代码>?如果包含本地文件,则不需要完整的URL。我希望函数仅在else块内有效,而不在else块外有效。有条件地定义isLoggedIn()
的原因是什么?您不能确保它只定义一次吗?这就是问题的根源。代码只是用来尝试修复它的,这个帐户来自functions.inc.phpif(!function_exists('isLoggedIn')){function isLoggedIn(){if(isset($_SESSION['loginid'])&&isset($_SESSION['username']){return true;//用户登录}否则{return false;//not logged}return false;}
它包括文件、所有html和一些php,但是函数不起作用,包含“/login.php”
文件或脚本没有问题,它是需要的"http://example.com/user/functions/functions.inc.php";代码>同样适用,如果您需要或包含URL而不是路径,那么如果php未配置为允许URL包含,则会出现致命错误;否则,您可能无法获得所需的功能代码;在大多数情况下,如果将目标服务器配置为以php.ahhh的形式提供.php文件,那么您只需在目标服务器上获得目标文件的已处理输出。我现在明白了,我只是花了一些时间来实现,我猜是深夜。
<?php
//error_reporting(0); // we don't want to see errors on screen
// Start a session
session_start();
require_once ("user/db_connect.inc.php"); // include the database connection
require_once ("user/functions/functions.inc.php"); // include all the functions
$seed="0dAfghRqSTgx"; // the seed for the passwords
$domain = "example.com"; // the domain name without http://www.
$prostat = "Offline";
if (function_exists('isLoggedIn')) {
}
else
{
function isLoggedIn()
{
if (isset($_SESSION['loginid']) && isset($_SESSION['username']))
{
return true; // the user is logged in
}
else
{
return false; // not logged in
}
return false;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Example | <?php echo $page; ?></title>
<link href="bootstrap.css" rel="stylesheet">
<link href="http://example.com/css/main.css" rel="stylesheet">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="http://example.com/js/buttons.js"></script>
<script type="text/javascript" src="http://example.com/js/main.js"></script>
</head>
<header>
<div class="nav">
<div class="container">
<ul class="pull-left">
<li><a href="http://example.com">Example</a></li>
<li><a href="#">Coming Soon!</a></li>
</ul>
<?php
include "http://example.com/login.php";
?>
include "http://example.com/login.php";