Help with PHP if statement

Associate
Joined
25 Apr 2006
Posts
202
Hello

I don't know much PHP and I'm trying to get a footer to display one way on one page, and another way on all the others. This is probably really basic and I'm sure I'm making a complete bosh of it. If someone could tell me how I should go about this I would be extremely grateful as usual.
 
Last edited:
PHP:
if ($_SERVER['REQUEST_URI'] == "X"){
<!-- Footer stuff for the one page -->
} else {
<!-- Footer stuff for everything else -->
}

If you're unsure of what X should be, just 'echo $_SERVER['REQUEST_URI']' on the page you need the separate footer for and that'll give you what you need.
 
PHP:
if ($_SERVER['REQUEST_URI'] == "X"){
<!-- Footer stuff for the one page -->
} else {
<!-- Footer stuff for everything else -->
}

If you're unsure of what X should be, just 'echo $_SERVER['REQUEST_URI']' on the page you need the separate footer for and that'll give you what you need.

Thanks for your post. I'm still having a bit of trouble with it. Perhaps you could take a look?

PHP:
	<?php
	if ($_SERVER['REQUEST_URI'] == "default.php")
	{
	?>
    
    <!--Home Page Footer-->
    <div class="footer">
        <div class="footerIcons">
            
        </div>
        <div class="footerTwitter">
            
        </div>
        <div class="footerMicroSites">
            
        </div>
        <div class="footerLinks">
            <?php
            include($DOCUMENT_ROOT."/includes/php/bottomlinks.php");
            ?>       
        </div>
        <div class="footerText">
            
        </div>
    </div>
    
    <?php } else { ?>
    
    <!--Blue Footer Image-->
    <div class="footer2">
	</div>
	
    <!--Footer-->
    <div class="footer">
        <div class="footerIcons">
            
        </div>
        <div class="footerTwitter">
            
        </div>
        <div class="footerMicroSites">
            
        </div>
        <div class="footerLinks">
            <?php
            include($DOCUMENT_ROOT."/includes/php/bottomlinks.php");
            ?>       
        </div>
        <div class="footerText">
             
        </div>
    </div>
    
	<?php
    }
    ?>

Basically I don't want the <!--Blue Footer Image--> to display on the home page. It isn't working at the moment but is there perhaps a better way of doing it?

Thanks
 
I've also tried to find the correct URL without any luck

I've set up a test page to try and get this to work:

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?PHP
echo $_SERVER['REQUEST_URI'];
echo "hello world";
?>
</body>
</html>
 
Just hello world:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
hello world</body>
</html>
 
Last edited:
OK when I used that I get this as the output

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
/test.phphello world</body>
</html>

and when I add it onto the page that I want to find the address for it gives me /default.php which if I put that in as '$_SERVER['REQUEST_URI'] == "/default.php' still doesn't work. When I view default.php it shows the
Code:
<!--Blue Footer Image-->
    <div class="footer2">
    </div>
 
:confused:

PHP:
if($_SERVER['SCRIPT_NAME'] == '/default.php') {

}

Yeah that works thanks! I was also advised to try

PHP:
if(strstr($_SERVER['PHP_SELF'], "default.php"))

Which also seemed to work but i'm not sure what it's doing exactly. I think I will go with your one though.
 
I have kindly been shown a simpler way of achieving what I want without the duplication of code:

PHP:
<?php
	/* add to all but homepage footer */
	if(!strstr($_SERVER['PHP_SELF'],"default.php")) 
	{
	?>
	<div class="footer2"></div>
	<?php 
	}
	/* display rest of footer */
	?>
	
    <div class="footer">
        <div class="footerIcons">
        </div>
        <div class="footerTwitter">
        </div>
        <div class="footerMicroSites">
        </div>
        <div class="footerLinks">
            <?php
            include($DOCUMENT_ROOT."/includes/php/bottomlinks.php");
            ?>       
        </div>
        <div class="footerText"> 
        </div>
    </div>

Seems to be working OK. Thanks for everyones help today.
 
Back
Top Bottom