I am trying to make my website display a different header depending on the page. If the page is 'index.php', it should include 'index-header.php'. If it isn't 'index.php', then it should include 'page-header.php'.

So far, I have the following code:

<?php
if($_SERVER[SCRIPT_NAME] == '/index.php'){include (index-header.php);}
else { include ('page-header.php');
?>

When I upload it, I get the following error:
'Parse error: syntax error, unexpected $end in /home/a3808hos/public_html/test/header.php on line 4'

Thanks for the help :D

Have you tried `beutifiying` your code?
eg:

/* Code: */
session_start(); if(isset($_SESSION['somevar'])){echo $_SESSION['somevar']; }else{echo 'othervar'; }
/* Would Be:*/
session_start();
if(isset($_SESSION['somevar'])) {
    echo $_SESSION['somevar'];
} else {
    echo 'othervar';
}

This often helps you to find errors in your code.
Also, use single quotes or double quotes unless using a variable or a variable created using

define();

.
And, if you don't notice it, you missed out the last curly brace to close the if...else statement.

Member Avatar for diafol
if($_SERVER[SCRIPT_NAME]...

change to

if(basename($_SERVER['PHP_SELF']) == 'index.php'){

the source of this error is the missing closing brace in line 3 as matthew wrote, errors are usually just before the reported line number
the missing quotes (per the OP) $_SERVER[[b]'[/b]variable[b]'[/b]] will cause another set of problems later
format is not optional

good code editors provide code highlighting that will negate this occurring again

the PHP manual is available online, as a downloadable text,chm ,any number of file types

perhaps, get the php manual and as a last resort, and, when nothing else works RTFM

<?php
if(basename($_SERVER['SCRIPT_NAME']) == 'index.php'){
include ('index-header.php');
} else {
include ('page-header.php');
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.