2013-05-21 44 views
0

我已經建立了一個函數,基本上鍊接到其相對帖子的摘錄。爲了做到這一點,我認爲變量$_SERVER['SERVER_NAME']可以派上用場,建立路徑。

我不知道這是由於我在本地環境測試頁面,但在本地機器上我的路徑是http://localhost/webdir/localhost/index.php?p=3localhost被重複兩次。什麼可能造成這種情況?

+2

不知道它是否有關,但它應該是'$ _SERVER' – galymzhan

+0

你如何建立這條道路? – Gumbo

+1

在webdir中可能有一個名爲localhost的目錄,你看過嗎? – vascowhite

回答

0

使用這樣

$link='http://'.$SERVER_['SERVER_NAME']; 

如果你不希望任何有價值的GET類型使用此

$l1=explode('?',$SERVER_['SERVER_NAME']); 
$link='http://'.$l1[0]; 

希望這有助於你。

+0

是的,謝謝!我擺脫了第二個'localhost'非常感謝你。 – haunted85

+0

不客氣。請參閱我的新答案。 –

1

嘗試連這個 編輯幾乎所有類型的URL的偉大工程..

<?php 
$l1=explode('?',$_SERVER["SERVER_NAME"]); 

$link='http://'.$l1[0]; 
echo $link; 
echo '<h2><center>Add users</center></h2>'; 
$pageURL = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://'; 
$pageURL1 = $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"] : $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
$pageURL=$pageURL.$pageURL1; 
//$pageURLt=explode('?',$pageURL);//Uncomment this and next line if you don't want get variable 
//$pageURL=$pageURL.$pageURLt[0]; 
echo $pageURL; 

?>