conditional php include

He has: 688 posts

Joined: Feb 2001

Hi. I want a javascript to only load on one page, my home index page. Problem is that I need to put this script (or an include to another file which contains the javascript) in the header file, which is used by every page. [see the snow effect on this page ] Is there a way to easily do this in php?

What I was thinking of doing is to put a small variable on my index page above the header include, who's presence (or value) would 'tell' the header file whether to include a javascript file. If the value is missing or not correct then it wouldn't do call the include. Like this: "if $usescript = yes, then include file "script"". (My header is a php extention so it can parse stuff) If this would work can somebody please help me out with the correct formatting?

Thanks.

mairving's picture

They have: 2,256 posts

Joined: Feb 2001

It should be pretty easy to do. Just do a test on the page and if the page is the home page /index.htm, then load the script.

<?php
if ($PHP_SELF == '/index.php') {

do
this script

}
?>

Mark Irving
I have a mind like a steel trap; it is rusty and illegal in 47 states

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.