Query bout Headers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lyasian
Forum Newbie
Posts: 1
Joined: Thu Nov 27, 2008 9:02 am

Query bout Headers

Post by lyasian »

Hi I've just been working on a site and I've got 2 different headers and want one of them to load up with the index page, and another that loads up with every other page, so I was just wondering if there was an if statement I could write for it to work. Something along the lines of

Code: Select all

 
if($Path="index.php") 
{
 require('header-index.php');}
  else
{
 require('header.php');}
 
All subpages run to pages like "index.php?s=about" and things like that, so whats above doesn't work as I'd like it to. Is there any way of setting it up so it'd run as something like

if the path is only index.php (an exact reference only) then it runs header-index.php, otherwise it runs just header.php.

Is there anything like that that'd work with it ? I've been trying to a while and can't get it to work, but its the last piece of the puzzle to finish off the site and I can't do it, please can anybody help.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Query bout Headers

Post by John Cartwright »

Code: Select all

if (basename($_SERVER['SCRIPT_FILENAME'] == 'index.php')) {
   require('header-index.php');
} else {
   require('header.php');
}
You were close, $_SERVER['SCRIPT_FILENAME'] returns the currently executed script, and base will will return the filename without it's filepath.

Edit | After re-reading your post, you would not like to include this if ?s= in the url is not present?

Code: Select all

if (basename($_SERVER['SCRIPT_FILENAME'] == 'index.php') && empty($_GET['s'])) {
   require('header-index.php');
 
   //load index page
} else {
   require('header.php');
 
   //load page from $_GET['s']
}
Post Reply