引导程序中的动态导航栏

Is it a good programming practice to write code for navigation bar in each file? or write it once and use forever using any server side scripting language like php.

There's a principle that us programmers use called DRY (Don't Repeat Yourself). If you can help it, it's best to write things only once and then use functions / methods to refer to the code, as opposed to writing the same thing over and over again.

The most common way of doing it with navbars is to put them in a header file, along with the scripts / stylesheets for your website, and then include them at the top of every page (or if your website is MVC then you could do it dynamically and include it from the Servlet).

The way of doing this in PHP is simple, and like so:

header.php

<link rel="stylesheet" href="style.css" />
// etc. etc. - this will include your navbar code

Then in your other pages, at the top, you simply write

<?php
include 'path/to/header.php';
//Other code specific to that page

Easy peasy :)