zapatista Posted August 3, 2010 Share Posted August 3, 2010 Hello I'm hoping someone here can help me with this. I know very little PHP I'm afraid but I think what I want to do is fairly basic and should be relatively simple. I have a footer which is referenced on each page of the site with <?php include($DOCUMENT_ROOT."/includes/php/footer.php"); ?> Within the footer I want it so that if it's the home page (default.php) it displays just the footer but for any other page I want it to display a Div and then the footer. Here is what I have so far but it isn't working: <?php if ($_SERVER['REQUEST_URI'] == "default.php") { ?> <!--Home Page Footer--> <div class="footer"> <div class="footer1"> </div> <div class="footer2"> </div> <div class="footer3"> </div> <div class="footerLinks"> <?php include($DOCUMENT_ROOT."/includes/php/bottomlinks.php"); ?> </div> <div class="footer4"> </div> </div> <?php } else { ?> <!--Blue Footer Image--> <div class="footer2"> </div> <!--Footer--> <div class="footer"> <div class="footer1"> </div> <div class="footer2"> </div> <div class="footer3"> </div> <div class="footerLinks"> <?php include($DOCUMENT_ROOT."/includes/php/bottomlinks.php"); ?> </div> <div class="footer4"> </div> </div> <?php } ?> I don't know that the request uri address is correct but when I've tried to use 'echo $_SERVER['REQUEST_URI']' to find out what it should be I can't get that to work either. I'm new here, this is my first post. Sorry if it's too basic or I've made a forum faux pas. Any help would be extremely appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/209658-help-with-php-if-statement/ Share on other sites More sharing options...
JonnoTheDev Posted August 3, 2010 Share Posted August 3, 2010 Try the following <?php if(strstr($_SERVER['PHP_SELF'], "default.php")) { } else { } ?> Quote Link to comment https://forums.phpfreaks.com/topic/209658-help-with-php-if-statement/#findComment-1094541 Share on other sites More sharing options...
zapatista Posted August 3, 2010 Author Share Posted August 3, 2010 Yes that has worked. Thank you very much! Would you be so kind as to explain what that is doing exactly? And is the way I've done it sensible in terms of duplicating the same code in the if and else with the only difference being the Div before the footer in the else? I have a feeling there might be a better way of doing it but being a novice I don't know what that is. Something like if page doesn't = default.php display the Div. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/209658-help-with-php-if-statement/#findComment-1094545 Share on other sites More sharing options...
JonnoTheDev Posted August 3, 2010 Share Posted August 3, 2010 Would you be so kind as to explain what that is doing exactly? Have a look at the following from the php manual and you will see. http://php.net/manual/en/reserved.variables.server.php http://uk3.php.net/strstr By duplicating the HTML your code is inefficient. Changes to the footer would mean you having to change 2 parts of the HTML instead of 1. If all that is needed is an additional div element you could use the following <?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="footer1"> </div> <div class="footer2"> </div> <div class="footer3"> </div> <div class="footerLinks"> <?php include($_SERVER['DOCUMENT_ROOT']."/includes/php/bottomlinks.php"); ?> </div> <div class="footer4"> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/209658-help-with-php-if-statement/#findComment-1094551 Share on other sites More sharing options...
zapatista Posted August 3, 2010 Author Share Posted August 3, 2010 By duplicating the HTML your code is inefficient. Changes to the footer would mean you having to change 2 parts of the HTML instead of 1. If all that is needed is an additional div element you could use the following Yes, that is what I was thinking. Thank you, I've done it how you suggested and it seems to work fine. I really appreciate you taking the time to help me, it's hard for me to fully express my gratitude through the medium of forum. Quote Link to comment https://forums.phpfreaks.com/topic/209658-help-with-php-if-statement/#findComment-1094563 Share on other sites More sharing options...
JonnoTheDev Posted August 3, 2010 Share Posted August 3, 2010 it's hard for me to fully express my gratitude through the medium of forum. I could give you my PayPal address! Only kidding Quote Link to comment https://forums.phpfreaks.com/topic/209658-help-with-php-if-statement/#findComment-1094575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.