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.

Quick Help for Rep++

Discussion in 'PHP' started by nkiegrea, Dec 14, 2007.

  1. #1
    Alright, heres the question.

    I have a script that runs off of the index.php.. It is my template.

    I want to have a intro paragraph that I ONLY want to show up when the user is at the main page.

    I have tried using these php codes to make it only show on the main page, but it continues to show up on all of the pages.

    <? $url=$_SERVER['REQUEST_URI'];
     
     $url=explode(".com",$url);
     
     $check=$url[1];
     
     if($check=="/")
     {
     echo "paragraph blah blah blah blah";
     }
    
    ?>
    PHP:
    and then,

    <? if ($_SERVER['REQUEST_URI']== "http://www.url.com");
    
    { 
                     echo "paragraph blah blah blah blah";
    				 
    				 } ?>
    PHP:
    Both of these didn't work, any ideas of why or what I can change to make them work.. or if I need to use something completely different.

    Anyone that can help will get a big thanks and a hug?. :D

    Thanks
    Zack B
     
    nkiegrea, Dec 14, 2007 IP
  2. danzor

    danzor Peon

    Messages:
    208
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Find out your SCRIPT_FILENAME variable, paste this into a file (which you can delete when you're done)

    <?php echo phpinifo(); ?>

    Find _SERVER["SCRIPT_FILENAME"], near the bottom. Copy the value of that.. e.g. /var/www/domain.com/index.php and paste it into $filename below

    Then

    <?php
    $filename = "/var/www/domain.com/index.php";
    if($_SERVER["SCRIPT_FILENAME"] = $filename && (count($_SERVER["argv"]) == 0)) {
    echo "paragraph";
    }
    ?>
    PHP:
    That should work.. it will only show if the query string is empty (i.e. index.php and not index.php?page=info)
     
    danzor, Dec 14, 2007 IP
    nkiegrea likes this.
  3. Shazz

    Shazz Prominent Member

    Messages:
    8,395
    Likes Received:
    453
    Best Answers:
    0
    Trophy Points:
    330
    #3
    Shazz, Dec 14, 2007 IP
  4. nkiegrea

    nkiegrea Peon

    Messages:
    355
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #4
    nkiegrea, Dec 14, 2007 IP
  5. nkiegrea

    nkiegrea Peon

    Messages:
    355
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I thought this would work.. but it sadly didn't... :-(

    Do you have any other ideas? Anyone else see why this wouldn't work?

    Any helps would be quite helpful!

    _Zack
     
    nkiegrea, Dec 14, 2007 IP
  6. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The operator is wrong, it should be '==' instead of '=' and i would include some additional brackets, ie:
    
    if(($_SERVER["SCRIPT_FILENAME"] == $filename) && (count($_SERVER["argv"]) == 0)) {
    
    Code (markup):
    If you only have 1 index.php, you could simplify the whole thing and use this:
    
    if (basename($_SERVER["SCRIPT_FILENAME"]) == "index.php")
    {
    	//your code
    }
    
    Code (markup):
     
    hogan_h, Dec 14, 2007 IP
    nkiegrea likes this.
  7. Hernan

    Hernan Peon

    Messages:
    45
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Try this

    <?php
    $file_path = substr($_SERVER['REQUEST_URI'], $ini_substr, strlen($_SERVER['REQUEST_URI']));
    $uri = explode('?', $file_path);
    if ($uri[0] == "/" OR $uri[0]== "index.php")
    {
    	echo "your paragraph";
    }
    ?>
    Code (markup):
     
    Hernan, Dec 14, 2007 IP
    nkiegrea likes this.
  8. nkiegrea

    nkiegrea Peon

    Messages:
    355
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #8

    This one worked like a charm... THANKS A LOT!

    You get a "hug"... and so does everyone else.. Thanks guys.

    This is why I love this forum.. resources at your finger tips! :cool:

    Regards,
    Zack B
     
    nkiegrea, Dec 15, 2007 IP
    hogan_h likes this.
  9. Hernan

    Hernan Peon

    Messages:
    45
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks for the hug :p
     
    Hernan, Dec 15, 2007 IP