title: PHP webpage navigation and active page
body: <p>i have template.php and i include navigation.php that in separate page to template  i want when i navigate through my website pages to be the page i'm on to be active with css style i want to be linked to css page to take active style link for my links.  </p>
  
  <p>here my naviation.php page.</p>
  
  <pre><code>   &lt;body&gt;
    &lt;?php 
      $directoryURI = $_SERVER['REQUEST_URI'];
      $path = parse_url($directoryURI, PHP_URL_PATH);
      $components = explode('/', $path);
      $first_part = $components[1];
       ?&gt;
  
      &lt;div id="navigation"&gt;
  &lt;div class="shell"&gt;
      &lt;ul&gt;
   &lt;li class="&lt;?php if ($first_part=="Home") {echo "active";  } else  {echo "noactive";}?&gt;"&gt;&lt;a href="Home.php"&gt; &lt;span&gt;HOME&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
   &lt;li class="&lt;?php if ($first_part=="About") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="About.php"&gt; &lt;span&gt;ABOUT&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
   &lt;li class="&lt;?php if ($first_part=="services") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="services.php"&gt; &lt;span&gt;SERVICES&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
   &lt;li class="&lt;?php if ($first_part=="Products") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="products.php"&gt; &lt;span&gt;Products&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
   &lt;li class="&lt;?php if ($first_part=="clients") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="clients.php"&gt; &lt;span&gt;Clients&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
   &lt;li class="&lt;?php if ($first_part=="contacts") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="contacts.php"&gt; &lt;span&gt;CONTACT&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
      </p>
  
  <p>here is my css style.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#navigation { background:#4073b9 url(images/navigation.gif) left top repeat-x; height:50px; }
  #navigation ul { list-style:none; }
  #navigation ul li { float:left; height:42px; line-height:42px;}
  #navigation ul li a { float:left; height:42px; line-height:42px; color:#fff; font-size:13px; font-weight:bold; text-decoration:none;  padding:0 0 0 33px;  }
  #navigation ul li a span { float:left; height:42px; line-height:42px; padding:0 33px 0 0; }
  #navigation ul li a:hover,
  #navigation ul li a.active { background:url(images/navigation-active.gif) left top no-repeat; }
  #navigation ul li a:hover span,
  #navigation ul li a.active span { color:#4073b9; background:url(images/navigation-active.gif) right top no-repeat; }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>   &lt;body&gt;
        &lt;?php 
          $directoryURI = $_SERVER['REQUEST_URI'];
          $path = parse_url($directoryURI, PHP_URL_PATH);
          $components = explode('/', $path);
          $first_part = $components[1];
           ?&gt;
          
          &lt;div id="navigation"&gt;
   &lt;div class="shell"&gt;
    &lt;ul&gt;
       &lt;li class="&lt;?php if ($first_part=="Home") {echo "active";  } else  {echo "noactive";}?&gt;"&gt;&lt;a href="Home.php"&gt; &lt;span&gt;HOME&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
       &lt;li class="&lt;?php if ($first_part=="About") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="About.php"&gt; &lt;span&gt;ABOUT&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
       &lt;li class="&lt;?php if ($first_part=="services") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="services.php"&gt; &lt;span&gt;SERVICES&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
       &lt;li class="&lt;?php if ($first_part=="Products") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="products.php"&gt; &lt;span&gt;Products&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
       &lt;li class="&lt;?php if ($first_part=="clients") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="clients.php"&gt; &lt;span&gt;Clients&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
       &lt;li class="&lt;?php if ($first_part=="contacts") {echo "active"; } else  {echo "noactive";}?&gt;"&gt;&lt;a href="contacts.php"&gt; &lt;span&gt;CONTACT&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
   &lt;/div&gt;
  &lt;/div&gt;
      &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>hope you can help me thank you.</p>