开发者

different title, keyword and description in every page's

How can I add a different title, keyword and description in every page's <head> of my simple php website dynamically?

I have included file header.p开发者_如何学Pythonhp in all of my pages, how can i know in what page the user in?

For example, I have php files register.php, and login.php, and I need different titles, keywords and descriptions.

I do not want use the $_GET method.

Thanks!


Set variables at the top of each page that will be read by header.php. Then insert the values of the variables in the right places in header.php. Here is an example:

register.php:

<?php
    $title = "Registration";
    $keywords = "Register, login";
    $description = "Page for user registration";

    include('header.php');
?>

header.php

<html>
    <head>
        <meta name="keywords" content="<?php echo $keywords; ?>" />
        <meta name="description" content="<?php echo $description; ?>" />
        <title><?php echo $title; ?></title>
    </head>
    <body>


Put the output inside a function (within your header.php) and insert its parameters at appropriate places into the markup.

function html_header($title = "Default") {
    ?><!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title><?php echo $title ?></title>
    </head>
    …
    <?php
}


you can try this:

for example the $page variable is your page name:

<?php
 switch($page) 
  {
    case 'home':
     $title = 'title';
     $keyword = 'some keywords..';
     $desc = 'description';
    break;
    case 'download':
     $title = 'title';
     $keyword = 'some keywords..';
     $desc = 'description';
    break;
    case 'contact':
     $title = 'title';
     $keyword = 'some keywords..';
     $desc = 'description';
    break;
  }

if(isset($title))
{
   ?>
 <title><?php echo $title; ?></title>
 <meta name="keywords" content="<?php echo $keyword; ?>" />
 <meta name="description" content="<?php echo $desc; ?>" />
 <?php
}
else
{
   ?>
 <title>default</title>
 <meta name="keywords" content="default" />
 <meta name="description" content="default" />
 <?php
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜