【问题标题】:Howto read currentpage after index.php?如何在 index.php 之后读取当前页面?
【发布时间】:2013-09-13 13:47:07
【问题描述】:

我想在我的代码、设置关键字、描述和页面标题方面获得一些帮助。

我的head.php(包含在index.php中):

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

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

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

在 index.php 中的菜单和包含语句如下:

**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>

我曾尝试使用$SERVER_[REQUEST_URI] 等来执行此操作,但我无法做到。

请帮助解决这个“问题”

【问题讨论】:

  • 我不确定 $SERVER_[REQUEST_URI] (应该是 $_SERVER['REQUEST_URI']; 无论如何)是否会照顾你正在尝试做的事情。我认为在您的 URL 情况下,您最好使用正则表达式检查。
  • 看起来您正在使用 JavaScript 通过您的 URL 的外观访问不同的页面。对吗?
  • 确实如此。我认为这会导致问题。

标签: php jquery html css


【解决方案1】:

您可以使用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;

    /* define more pages here */

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

【讨论】:

  • 是的!非常有帮助!
  • 只需在切换前打印出$urlFragment (var_dump( $urlFragment );) 以检查其内容...
  • 如果我使用下面的代码,什么都不会出现:
  • 已检查。如果我使用 case '': 它会给我默认信息。所以..它是空的并且一直是空的..为什么? :)
  • ??你能帮我解决这个问题吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多