如何读取index.php后的当前页面? [英] Howto read currentpage after index.php?

查看:167
本文介绍了如何读取index.php后的当前页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对我的代码有一些帮助,设置关键字,页面的描述和标题。



我的head.php(包含在索引中。 php):

 <?php 
$ current = $ SERVER_ [REQUEST_URI];
$ home =/#!/ page_HOME;
if($ current == $ home){
$ title =Example.com || Home;
$ keywords =some words;
$ description =description text;
}
?>

我的网站使用'strange'URL,例如: http:// example .com / index.php#!/ page_HOME
是一个带有CSS和jQuery技巧来加载不同页面的网页。



现在我想更改页面的关键字,描述和标题通过点击菜单链接。



在index.php中,菜单和include语句如下:

  **菜单中的链接:** 
< a href =#!/ page_HOME>首页< / a>
**包含在网页中:**
< li id =page_HOME>
< a href =#!/ page_SPLASHclass =close>< / a>
<?php include('home.html'); ?>
< / li>

我试图用 $ SERVER_ [REQUEST_URI] code>等等,但我不能管理。



请帮助解决这个问题

您可以使用 parse_url()来检索锚点片段(#之后的所有内容)请参阅: http://php.net/parse_url

  $ url ='http://'。 $ _SERVER ['HTTP_HOST']。 $ _SERVER ['REQUEST_URI']; 
$ urlFragment = parse_url($ url,PHP_URL_FRAGMENT);

switch($ urlFragment)
{
case'!/ page_SPLASH':
$ title =Example.com || Splash;
$ keywords =splash content;
$ description =splash description text;
break;

/ *在这里定义更多页面* /

case'!/ page_HOME':/ * no break;预期* /
默认值:
$ title =Example.com || Home;
$ keywords =some words;
$ description =description text;
break;
}


I'd like to have some help with my code, setting keywords, description and title of the page.

My head.php (included in the index.php):

<?php 
$current = $SERVER_[REQUEST_URI];
$home = "/#!/page_HOME";
if($current==$home) {
  $title = "Example.com || Home";
  $keywords = "some words";
  $description = "description text";
}   
?>

My websites uses 'strange' URL, like: http://example.com/index.php#!/page_HOME . Is is a webpage with CSS and jQuery tricks to load the different pages.

Now I'd like to change the keywords, description and title of the page by clicking on the menu link.

In the index.php the menu and include statements are like this:

**link in menu:** 
<a href="#!/page_HOME">Home</a>
**include in webpage:** 
<li id="page_HOME">
    <a href="#!/page_SPLASH" class="close"></a>  
    <?php include('home.html'); ?>
</li>

I've tried to do this with $SERVER_[REQUEST_URI] and so on, but I can't manage.

Please help solving this 'problem'

解决方案

You can retrieve the anchor fragment (everything after #) by using parse_url(); see: http://php.net/parse_url

$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$urlFragment = parse_url( $url, PHP_URL_FRAGMENT );

switch( $urlFragment )
{
    case '!/page_SPLASH':
        $title = "Example.com || Splash";
        $keywords = "splash content";
        $description = "splash description text";
        break;

    /* define more pages here */

    case '!/page_HOME': /* no break; intended */
    default:
        $title = "Example.com || Home";
        $keywords = "some words";
        $description = "description text";
        break;
}

这篇关于如何读取index.php后的当前页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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