简体   繁体   English

为什么在访问另一个PHP文件时出现PHP文件错误?

[英]Why I'm getting errors of a PHP file while I am accessing another PHP file?

I have a problem in my php script. 我的php脚本有问题。 The problem is in loginpage.php. 问题出在loginpage.php中。 I have addcategory.php and it runs fine with no error. 我有addcategory.php,它运行正常,没有错误。 But, whenever i try to access loginpage.php, it shows the url of loginpage.php but throws error message in error.log file related to addcategory.php. 但是,每当我尝试访问loginpage.php时,它都会显示loginpage.php的网址,但会在与addcategory.php相关的error.log文件中引发错误消息。 The message is like: 消息就像:

PHP Warning:  include(../session.php): failed to open stream: No such file or directory in /var/www/RamroDeal/php/controller/admin/addcategory.php on line 2

PHP Warning:  include(): Failed opening '../session.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/RamroDeal/php/controller/admin/addcategory.php on line 2

PHP Warning:  include(../../view/fns.php): failed to open stream: No such file or directory in /var/www/RamroDeal/php/controller/admin/addcategory.php on line 3

PHP Warning:  include(): Failed opening '../../view/fns.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/RamroDeal/php/controller/admin/addcategory.php on line 3

and There was another error message before these above error messages. 并且在上述这些错误消息之前还有另一个错误消息。 It's as follow 如下

Cannot redeclare __autoload() (previously declared in /var/www/RamroDeal/php/controller/loginpage.php:5) in /var/www/RamroDeal/php/controller/admin/addCategory.php on line 8, referer: http://localhost/RamroDeal/php/index.php

I don't understand why it is accessing addcategory.php when i'm requesting for loginpage.php. 我不明白为什么当我请求loginpage.php时它正在访问addcategory.php。 Please help!!! 请帮忙!!!

The php page are given below php页面如下

loginpage.php loginpage.php

session_start();
include '../view/fns.php';

spl_autoload_register(function ($obj)
{
    $class = strtolower($obj);
    include '../class/'.$class.'.php';
});

$msg = '';
if (isset($_POST['email']) && isset($_POST['pw']))
{
    $filter = Validation::getValidationInstance();
    $email = $filter->filter($_POST['email']);
    $pw = $filter->filter($_POST['pw']);

    $login = Log::getLogInstance();

    $login->setProperty($email, $pw, Database::getDBInstance());

    $msg = $login->login();
}

//Displaying heading part of html
ramrodeal_header("Login - RamroDeal - Great Deal, Great Price");

//Displaying navigation part of html
nav();

if (empty($_SESSION['email']))
{
    //Displaying login form
    login_form();
    echo $msg;
} else{
    switch($_SESSION['type']){
        case 'administrator':
            $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/admin/adminHomepage.php';
            header('Location: ' . $home_url);('Location: ' . $home_url);
            break;

        case 'sub-administrator':
            $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/admin/subAdminHomepage.php';
            header('Location: ' . $home_url);('Location: ' . $home_url);
            break;

        case 'merchant':
            $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/merchant/merchantHomepage.php';
            header('Location: ' . $home_url);('Location: ' . $home_url);
            break;

        case 'agent':
            $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/agent/agentHomepage.php';
            header('Location: ' . $home_url);('Location: ' . $home_url);
            break;

        default:
            $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/customer/customerHomepage.php';
            header('Location: ' . $home_url);('Location: ' . $home_url);
    }
}

//Displaying footer of html
ramrodeal_footer();

addcategory.php addcategory.php

include('../session.php');
include('../../view/fns.php');

spl_autoload_register(function ($obj)
{
    $class = strtolower($obj);
    include '../../class/'.$class.'.php';
});


//Displaying heading part of html
ramrodeal_header("RamroDeal - Great Deal, Great Price");

//Displaying navigation part of html
nav();

//displaying add category form
addCategory();

$dealcategory = Category::getCategoryInstance(Database::getDBInstance());

if (isset($_POST['submit'])){
    $filter = Validation::getValidationInstance();
    $name = $filter->filter($_POST['name']);

    $dealcategory->setProperty($name);
    $msg = $dealcategory->addCategory();
    echo $msg;
}

$deallist = $dealcategory->getCategory();

categoryTable($deallist);

//Displaying footer of html
ramrodeal_footer();

UPDATE: 更新:

Both pages have different directory structure 两个页面的目录结构不同

loginpage.php is in var/www/myapp/php/controller/ loginpage.php位于var / www / myapp / php / controller /中

addcategory.php is in var/www/myapp/php/controller/admin/ addcategory.php位于var / www / myapp / php / controller / admin /中

检查view/fns.php ,为什么它包含addcategory.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM