Alternate header image?

Discussion in 'PHP' started by i.run.shit, Jul 2, 2009.

  1. #1
    I need to alternate a header image depending upon the page on a website I am working on. Unfortunately I absolutely nothing about PHP and really need some help here. I asked customer support and they told me to add:

    <?php
        $mypage = strtolower($this_filename);
        switch ($mypage){
            case "pagename1.php":
            $header_image = "some_file1";
            break;
    
            case "pagename2.php":
            $header_image = "some_file2";
            break;
    
            case "pagename3.php":
            $header_image = "some_file3";
            break;
    
            case "pagename4.php":
            $header_image = "some_file4";
            break;
        }
    ?> 
    Code (markup):
    I've tried this out, only changing the $header_image = "some_file" and the case "pagename.php" to my own image paths and file names. Unfortunantly, it does nothing for me and I really don't know where I am going wrong because, as I have said I know NADA about PHP but I really need this to work so I don't have to attempt to edit each page. I have Googled this for hours and am no closer to really understanding it.

    For instance,
    $mypage = strtolower($this_filename);
    Code (markup):
    means nothing to me.

    Can anyone help me, please?

    - Theresa
     
    i.run.shit, Jul 2, 2009 IP
  2. HorseGalleria

    HorseGalleria Peon

    Messages:
    91
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try using $_SERVER['SCRIPT_FILENAME'].
     
    HorseGalleria, Jul 2, 2009 IP
  3. gunbound

    gunbound Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you should learn html first, then javascript, php, flash... :)
    $mypage = strtolower($this_filename); //convert filename to lower case
     
    gunbound, Jul 2, 2009 IP
  4. i.run.shit

    i.run.shit Peon

    Messages:
    61
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I know html and css, slowly but surely attempting to learn javascript (I'm not an idiot, I just don't know PHP). And I have already tried the script, exactly as you see it, lowercase everything (because that's what xhtml has taught me :p) except adding my own image paths etc.

    This is basically what I have coded.

    <?php
        $mypage = strtolower($this_filename);
        switch ($mypage){
            case "pagename1.php":
            $header_image = "imgs/some_file1.gif";
            break;
    
            case "pagename2.php":
            $header_image = "imgs/some_file2.gif";
            break;
        }
    ?>
    
    Code (markup):
     
    i.run.shit, Jul 3, 2009 IP
  5. ajaymisrad

    ajaymisrad Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Your code looks fine except that the variable $this_filename is unassigned.

    Try the following code:
    <?php
        $this_filename = $_SERVER['PHP_SELF'];
        $mypage = strtolower($this_filename);
        switch ($mypage){
            case "pagename1.php":
            $header_image = "imgs/some_file1.gif";
            break;
    
            case "pagename2.php":
            $header_image = "imgs/some_file2.gif";
            break;
        }
    ?>
    
    Code (markup):
    For this code to work, you need to make sure the php script (pagename1.php etc.) and the "imgs" folder are in the same directory.


     
    ajaymisrad, Jul 3, 2009 IP