Menu - Making a website header

Implementing PHP

By: For: ComputerMentor Published: 13 July, 2016 Modified: 13 July, 2016

If you are like me a few weeks ago, you have a webhost who support PHP. You have greate Idèas, but after countless Google searches you still havent found out how to actually embed/implement it

That is exactly how I experienced PHP for the first time. Hopefully this site will guide you better than internet guided me.

Getting your Computer PHP ready

The first obvious thing to do it changing all those .html files into .php. It wont affect the content in any way, but you might notice that your browser cant read them anymore. That is because PHP is a server sided language.

Luckely there is an easy fix for that. Several programs let you launch a local Apache server on your computer. I like to use XAMPP. All you need to do is download -> install -> start Apache and you type localhost in your browser and you see the webpages again.

If you are on Windows your localhost is "C:\xampp\htdocs". You can change the folder to your preferred folder.

Where exacly do the "PHP" go?

So you changed your files and managed to see them using a local Apache server. Time to implement some code!

PHP is written anywhere in the webpage dokument, inside the <html></html> tags. One example down below where the first PHP code fetches a navbar, while the second one create a paragraph.

index.php file

<!DOCTYPE html>
    <title>Page Title</title>
      <nav id="navbar">
        <?PHP include("includes/navbar.php"); ?>

        <h1>My Simple Webpage</h1>
          I am a normal paragraph
          <?php echo '<p>And a PHP created paragraph</p>'; ?>

        Registred Trademark

navbar.php file inside includes folder

  <li><a href="/home.php>Home</a></li>
  <li><a href="/about.php>About</a></li>
  <li><a href="/contact.php>Contact</a></li>


Notice how the navbar.php file only have the relevant code and nothing more. the <?PHP include(location); ?> code gets replaced with anything it include. You can now design your navbar using the #navbar ID with CSS.

What can you place in .php files?

You can place anything you want inside php file's you include, as long as it is something the webpage can render. Everything from HTML code, PHP code, text and even javascripts.

Some of the most interesting and handy for a newbie is meta tags, the header, your navigation bar and footer. Nothing is worse than finding a change you really want for your website, only to realize you have to change 10+ pages.

Hope you learned something!
If you find any typos, got questions or just want to say hi, please do so in the comment section below :) Dont forget to like and share