2012-03-22 309 views
0

ABSPATH(絕對路徑

function abspath() 
{ 
    echo $_SERVER['DOCUMENT_ROOT']; 
} 

目錄(

function directory() 
{ 
    echo '/folder/'; 
} 

代碼行: -

header('Location:'.abspath().directory()); 

給了我以下的輸出:

C:/xampp/htdocs/folder/ 

當我使用

header('Location:'.$_SERVER['DOCUMENT_ROOT'];.directory()); 

它把我送到我的index.php在C:/xampp/htdocs/folder/index.php 爲什麼它不使用函數?

我想去C:使用此

header('Location:'.abspath().directory()); 

/xampp/htdocs/folder/index.php - 有什麼問題嗎?

回答

2

的問題是,你的職責是echo荷蘭國際集團的輸出,而不是返回它。你要改變你的功能:

function abspath() 
{ 
    return $_SERVER['DOCUMENT_ROOT']; 
} 

function directory() 
{ 
    return '/folder/'; 
} 

所以,你可以使用return ED值(即$_SERVER['DOCUMENT_ROOT']或「/文件夾/」,在這種情況下)在您的字符串concatentiation。

+0

謝謝克里斯工作:) – 2012-03-22 12:07:42

0

使用header時,您的路徑應該是URI。

Soething像

header('Location:http://yourpath.com/folder'); 

在回答您使用的是物理位置位於

文件嘗試$_SERVER["REQUEST_URI"]