Hello guys
I want to create something like SEO link i have website with three pages, but the header is the same
header.php

<!DOCTYPE html>
<html>
<head>
    <style>
        .active{
            background-color: #365214;
        }
        ul{
            display: inline;
        }
        li{
            display: inline;
        }
    </style>
    <title></title>

</head>
<body>
<ul>
    <li><a class="active" href="index.php">HOME</a></li>
    <li><a href="a.php">ABOUT</a></li>
    <li><a href="s.php">SERVICES</a></li>
    <li><a href="c.php">CONTACT</a></li>
    </ul>

footer.php

</body>
</html>

index.php

<?php
include("header.php");
include("home.php");
include("footer.php");
?>

what I need is when user click on any link on header it changed the title of page dynamically

<title></title>

and applying .active class to current page link.

Member Avatar for diafol

for simple one...

<?php
$pageArray = array(
        "home" => array("label"=>"home","url"=>"pages/index.php","title"=>"...","nav"=>'/home/'),
        "about" => array("label"=>"about","url"=>"pages/a.php","title"=>"...","nav"=>'/about/'),
        "services" => array("label"=>"services","url"=>"pages/s.php","title"=>"...","nav"=>'/services/'),
        "contact" => array("label"=>"contact","url"=>"pages/c.php","title"=>"...","nav"=>'/contact/'),
    );

$chosen= (isset($_GET['page']) && in_array(strtolower($_GET['page']), array_keys($pageArray))) ? $_GET['page'] : 'home';
$page = $pageArray[$chosen];

include("header.php");
include($page['url'] . ".php");
include("footer.php");
?>

Your header file could contain something like...

<?php
    $nav = '';
    foreach($pageArray as $key=>$item)
    {
        if(isset($item['nav']))
        {
            $cls = ($chosen == $key) ? ' class="active"' : ''; 
            $nav .= "\n\t<li><a$cls href="{$item['nav']}">".strtoupper($item['label'])."</a></li>";
        }
    }
?>

<!DOCTYPE html>
<html>
<head>
    <style>
        .active{
            background-color: #365214;
        }
        ul{
            display: inline;
        }
        li{
            display: inline;
        }
    </style>
    <title><?php echo $page['title'];?></title>
</head>
<body>
<ul>
    <?php echo $nav;?>
</ul>

You can now use a mod_rewrite having just a single index page - calling different include files depending on the rewritten url, e.g.

www.example.com/home/ which is: www.example.com/index.php?page=home
www.example.com/about/ which is: www.example.com/index.php?page=about
www.example.com/contact/ which is: www.example.com/index.php?page=contact
www.example.com/services/ which is: www.example.com/index.php?page=services

Just a matter of a simple .htaccess file.

I've Created .htaccess file for "title" I thought there is another solution :P
but this solve my .active class issue.
Thanks for you Sir, you are amazing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.