0

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

5
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by cwarn23
0

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.

Edited by Matthew N.: n/a

1
if($_SERVER[SCRIPT_NAME]...

change to

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

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

Edited by almostbob: n/a

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

Edited by cwarn23: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.