2016-12-14 39 views
0

我一直在为我的网站制作一个header.php文件,并且希望页面的标题标签根据您访问的页面进行更改。正确地在PHP函数中源代码页面

它似乎只适用于首页!

这是我写的函数:

<?php 

$directoryURI = $_SERVER['REQUEST_URI']; 
$path = parse_url($directoryURI, PHP_URL_PATH); 
$components = explode('/', $path); 
$first_part = $components[1]; 

$title = ""; 
$jumbotitle = ""; 
    $url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
if(strpos($url, '/') !== false){ 
    $title = "Home"; 
    $jumbotitle = "Home"; 
}if(strpos($url, 'about') !== false){ 
    $title = "About"; 
    $jumbotitle = "About"; 
} 
if(strpos($url, 'contact') !== false){ 
    $title = "Contact"; 
    $jumbotitle = "Contact"; 
} 

?> 

有什么建议?

+1

去你家和回声'$ url' ...最新输出? – Twinfriends

回答

-2

首先$_SERVER[REQUEST_URI]应该足够

$url = $_SERVER[REQUEST_URI]; 

请告诉我们,什么是现在$ url值?

+0

这个伎俩!谢谢一堆 –

+0

但为什么倒票?我的回答不完整。 – HubertS

+0

不知道!无论如何,我的名声太低而无法投票。你解决了我的问题,但:) –