SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Houston, TX USA
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Graphics and HTTP_REFERER

    I have a situation where I have separated my site into header.php, main.php and footer.php. Here's my index.php code:
    PHP Code:
    <?php
    include('header.php');
    include(
    'main.php');
    include(
    'footer.php');
    ?>
    Subsequent pages will all include header.php and footer.php, logically. So here's my problem: I have a layout issue where I need a graphic to appear in the header.php file ONLY if it's on index.php and not on any other page in my site. Is there a way to do this? I tried using this:
    PHP Code:
    <?php if($_SERVER['HTTP_REFERER'] == "index.php") { echo "<div id=\"graphicUsedOnce\"><img src=\"images/graphic.jpg\" width=\"10\" height=\"175\"></div>"; } ?>
    But it doesn't work. Any ideas would be greatly appreciated.

  2. #2
    SitePoint Addict Ramiro S's Avatar
    Join Date
    May 2003
    Posts
    321
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try with $_SESSION['PHP_SELF']
    Quasar - Web Development - Free Avatars

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Houston, TX USA
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ramiro S
    Try with $_SESSION['PHP_SELF']

  4. #4
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's $_SERVER['PHP_SELF'] so try:
    PHP Code:
    <?php
    if($_SERVER['PHP_SELF'] == '/index.php') {
        echo 
    '<div id="graphicUsedOnce"><img src="/images/graphic.jpg" width="10" height="175"></div>';
    }
    ?>

  5. #5
    SitePoint Zealot ceefour's Avatar
    Join Date
    Feb 2005
    Location
    Bandung, Indonesia
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    $displayHeaderImage = TRUE;
    include('header.php');
    include('main.php');
    include('footer.php');
    ?>

    on header.php:

    if (!empty($displayHeaderImage)) {
    /// do whatever you want here..
    }

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2004
    Location
    Houston, TX USA
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ceefour
    <?php
    $displayHeaderImage = TRUE;
    include('header.php');
    include('main.php');
    include('footer.php');
    ?>

    on header.php:

    if (!empty($displayHeaderImage)) {
    /// do whatever you want here..
    }
    Beautiful -- thanks!

  7. #7
    SitePoint Zealot ceefour's Avatar
    Join Date
    Feb 2005
    Location
    Bandung, Indonesia
    Posts
    138
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyway my sample code uses global variables which is something that I wouldn't suggest.
    I would suggest creating a "dummy" class or whatever, and put that as a static member variable.
    If your PHP can't handle static member variables, then use a singleton class and use a normal member variable...

    ..or else.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •