Jump to content

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/209658-help-with-php-if-statement/
Share on other sites

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?

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>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.