i have an application in which i have created a header.php
which is obviously common for all the pages in the app which i include on top of every other page. This header file contains the html
head tags and DOCTYPE
declaration etc and some common JS and CSS files needed for every page. But there are some specific files which i want to include depending on the page.
Now, how do i include a specific JS or CSS file based on the url from which the header.php
is requested.
I tried to use $_SERVER['PHP_SELF']
at the top of header file to fetch the url but it did not work.
Please suggest with the best technique that should be used in this situation.
Sample Code
header.php
<?php
include (dirname(__FILE__) . "/includes/functions.php");
$url = $_SERVER['REQUEST_URI'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>My APP</title>
<meta charset="utf-8" />
<meta name="robots" content="noodp, noydir" />
<meta http-equiv="X-Frame-Options" content="deny" />
<link rel="stylesheet" href="css/main.css" type="text/css" />
<script src="js/main.js"></script>
<?php
if($url == "teachers.php"){
echo "<script src='js/teachers.js'></script>";
}
?>
</head>
<body>