1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need to output text only if it's the homepage, fast help needed :)

Discussion in 'PHP' started by Fking, Sep 19, 2011.

  1. #1
    My php is quite rusty, i need quick fix for how tho show text only if you are on the homepage (index.php)
    Here is what i've come up so far, the problem is that it ALWAYS outputs the text, not only for the homepage

    function curPageName() {
     return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
    }
    
    if (curPageName() == 'index.php') {echo 'kef';}
    Code (markup):

    there should be something small i got wrong?
     
    Solved! View solution.
    Fking, Sep 19, 2011 IP
  2. #2
    <?php
    $cp = $_SERVER['REQUEST_URI'];
    if($cp=="/" || $cp=="/index.php" || $cp=="" )
    { echo "hello" }
    ?>

    I hope it helps

    Regards

    Alex
     
    kmap, Sep 19, 2011 IP
    Fking likes this.
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    Very small. Only put the code in index.php. Don't reference it on other pages.
     
    Rukbat, Sep 19, 2011 IP
  4. Fking

    Fking Active Member

    Messages:
    257
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4

    Thank you, the most elegant solution! Works perfect!


    @Rukbat, obviosly that's not an option :)
     
    Fking, Sep 19, 2011 IP