2014-10-28 83 views
-1

我遇到問題,包括Auth.php。該文件位於該確切的位置,這是我的WWW網站的根。PHP需要一次

指定$config變量沒有問題。

我的代碼:

<?php 

include("./head.inc"); 

    // start a new session (required for Hybridauth) 
    session_start(); 

    // change the following paths if necessary 
    $config = dirname(__FILE__) . '/www.bommachine.co.uk/site/modules/ProcessHybridAuth/hybridauth/config.php'; 
    require_once("/www.bommachine.co.uk/site/modules/ProcessHybridAuth/hybridauth/Hybrid/Auth.php"); 

我的錯誤:

Compile Error: require_once(): Failed opening required '/www.bommachine.co.uk/site/modules/ProcessHybridAuth/hybridauth/Hybrid/Auth.php' (include_path='.:/usr/share/php:/usr/share/pear') (line 11 of /var/www/www.bommachine.co.uk/site/templates/Test.php) 

不知道什麼是最好的,最安全的,爲什麼解決這個問題。

+0

你是不是想要在你的'require_once'調用中做同樣的事情? – 2014-10-28 13:35:17

+0

你不要在'require_once'中使用$ config var – 2014-10-28 13:35:47

+1

它看起來好像在你正在分配配置變量的那一行中,你正在預先設置一個'/ wwww ...'的路徑,這會使它成爲相對的。在第二種情況下,您使用的是require_once,但是,您正在使用'/ www ...'作爲絕對路徑。所以你可能想把它改成require_once(dirname(_ _ FILE _ _)。'/ www ....') – rethab 2014-10-28 13:36:23

回答

0

您可以使用您已經使用的方法,在此定義$config。指定包含基本目錄的常數:你需要需要的文件

define('BASEPATH', dirname(__FILE__)); 

然後用這個:

require_once(BASEPATH . "/www.bommachine.co.uk/site/modules/ProcessHybridAuth/hybridauth/Hybrid/Auth.php"); 

但是,請注意,__FILE__將包含完整的文件路徑中你正在使用這個Magic constant。如果你在/var/www/index.php中使用它,這將是路徑。如果你在/var/www/subdir/file.php中使用它,這將是__FILE__的值。

+1

自PHP版本5.3.0起,還有'__DIR__'。只需使用它並保護你自己的一些代碼;) – ToBe 2014-10-28 14:44:15