错误500 Require_once [英] ERROR 500 Require_once

查看:672
本文介绍了错误500 Require_once的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的作品的PHP code的:

this is my piece of php code:

<?php
require_once 'php/Classes/User/UserDataBaseManager.php';
require_once 'facebook/src/facebook.php';
?>

当我尝试浏览HTTP在此code:/mydomain/myfile.php然后在浏览器返回一个错误500

And when I try to browse this code in http:/mydomain/myfile.php then the browser return an error 500.

Apache日志说:

Apache log says:

[周三4月18日20时38分07秒2012] [错误] [客户端190.50.81.189] PHP致命错误:require_once()&LT; A HREF ='function.require'&GT;功能.require&LT; / A&GT;]:无法打开需要的PHP /类/数据库/ DataBaseManager.php'(include_path中=':在/ usr /共享/梨:在/ usr /共享/ PHP的')在/ var / WWW / virtuales /blyxo.com/php/Classes/User/UserDataBaseManager.php

解决方案?

推荐答案

这是什么样子让我看到文件UserDatabaseManager.php试图包括DataBaseManager.php但它提供了错误的道路。 Apache的错误表明它会首先在看即当前目录,然后的/ usr /共享/梨然后的/ usr /共享/ PHP

What this looks like to me is that the file UserDatabaseManager.php is trying to include DataBaseManager.php but it is providing the wrong path. Your apache error indicates that it will first look in . i.e. the current directory then /usr/share/pear then /usr/share/php

您DataBasemanger.php文件是不是无论是在过去两年的。当它试图在它包括你的相对路径当前目录的样子。因此,当你UserDataBaseManager.php文件(这是在 PHP /班/用户/ )提供了路径,然后阿帕奇结束在<$ C $找你DataBaseManager.php文件C> PHP /班/用户/ PHP /类/数据库/ DataBaseManager.php

Your DataBasemanger.php file is not in either of the last two. When it attempts to look in the current directory it is including your relative path. So when your UserDataBaseManager.php file (which is in php/Classes/User/) provides that path then apache ends up looking for your DataBaseManager.php file in php/Classes/User/php/classes/DataBase/DataBaseManager.php

有几种方法来解决这个。你可以得到的文档根目录和prePEND它的每一个包括这样

There are several ways to approach this. You could get the document root and prepend it to every include like this

$root = $_SERVER['DOCUMENT_ROOT'];
require_once($root . "/php/classes/DataBase/DataBaseManager.php");

或者,如果这个程序是在受控环境中,您可以编辑php.ini文件可以定义包括路径,也期待在 /var/www/virtuales/blyxo.com/php/类/ ,只包括与文件

require_once("Database/DataBaseManager.php");

有一个更好的解决办法可能是定义一个__autoload函数都会被调用尝试实例化一个新的对象,并把它用一些逻辑来查找文件,包括时间。该解决方案将需要更多的调整,但你可能会考虑它。这里是定义自己的自动加载程序 http://us2.php.net的文档/manual/en/function.autoload.php

A better solution might be to define an __autoload function that will be called every time you try to instantiate a new object and have it use some logic to look for the file to include. This solution would take a bit more restructuring but you might consider it. Here is the doc on defining your own auto loader http://us2.php.net/manual/en/function.autoload.php

我知道有其他方法可以做到这一点。让我知道什么对你的作品!

I know there are other ways to do this. Let me know what works for you!

这篇关于错误500 Require_once的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆