Hello , i have php script and i need to appear message to my visitors in all script pages ...but not in index page i used this code <?php if (basename($_SERVER["SCRIPT_NAME"]) != "index.php") { echo "<p>My wanted Message</p>"; } ?> PHP: but still message appear in all pages
To display the message on any page but not the index.php: <?php if (basename($_SERVER['SCRIPT_FILENAME']) != 'index.php'): ?> <p>My wanted Message</p> <?php endif; ?> PHP: To display a message only on the index.php: <?php if (basename($_SERVER['SCRIPT_FILENAME']) == 'index.php'): ?> <p>My wanted Message</p> <?php endif; ?> PHP: http://php.net/manual/en/language.operators.comparison.php Note: You can either use $_SERVER or the predefined constant (__FILE__) - in this case I used $_SERVER.
I use this to pull different titles when different php scripts are shown, but you could use it for anything I guess. example: at the top of a file say index.php I would put something like: $thispage = 'home'; PHP: ..and then in the header section or in your case where you want the message, I would put. <?php if ( $thispage == 'home' ) { echo "<p>My wanted Message</p>"; }else{ // or do something else }?> PHP: I know its basic, but it works just fine for me, you just have to name your php files, in your case the script page file.