致命错误:调用未定义的函数isLoggedIn()

时间:2014-11-17 19:41:53

标签: 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";

?>

的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>';
}
?>

footer.php

</body>
<footer>
    <p>&copy;<a href="***" title="***">***</a> 2014 - <?php echo date("Y"); ?> All Rights Reserved</p>
</footer>
</html>

的header.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";
          ?>

然而,我所做的任何功能都不起作用,我需要这些功能以及所有我将用它的链接更新它的功能,因为它的代码太多了!

我想知道为什么我可以包含/要求.php文件,但是我不能从它们调用函数? 你的来源是什么?

1 个答案:

答案 0 :(得分:2)

如果您的php.ini文件中没有启用URL包含包装器,则包含URL 会导致致命错误。请参阅:http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-include

假设login.php实际上与其他脚本位于同一服务器上,则应使用正确的本地路径包含它, NOT HTTP URL 使用绝对或相对路径; PHP还将使用php.ini配置中配置的任何路径。

更多信息:

http://php.net/manual/en/function.include.php

当您故意包含HTTP网址时,就像在代码中一样:

include "http://example.com/login.php";

您通常无权访问login.php文件中的函数,因为该文件将首先在目标服务器上处理,您将从该脚本中包含“输出”。