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.

php include query...

Discussion in 'PHP' started by ian_ok, Dec 18, 2004.

  1. #1
    I'm doing some testing with the php include so I can just have 1 menu and update in one location and for it to take effect over all pages....

    my side_menu is located in the root directory and works fine with files within that root directory.

    ....BUT...

    When I add the side_menu to a file within a folder the images on my side menu do not show....yes I know the path has changed.

    But does this mean for each different path stage I need a new side_menu that will show the images with the correct path.

    eg.

    root: side_menu.html

    root/folder: side_menu1.html

    root/folder/sub_folder: side_menu2.html

    Or is they a better way around this...Or should I remove the images!!

    Ian
     
    ian_ok, Dec 18, 2004 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Hi Ian

    Don't give up on the menu, it's a great idea.

    Firstly... the images can be absolute paths so if I can see an image at
    http://mysite.com/images/menu/home.gif
    by calling it in my browser I can either use that in my menu or
    /images/menu/home.gif

    The benefit is the first / which tells the browser to go to the root of the domain and start looking from there - not from whereever it happens to be.

    Never, ever, user ../images/menu/home.gif - it's bad for the search engine bots and may end up with broken links.

    Now, I've been talking about images because you mentioned them, the same goes for pages: give them all their full links, then it doesn't matter where your menu is located, it will always work.

    good luck!

    Sarah
     
    sarahk, Dec 19, 2004 IP
  3. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Sarah,

    It came to me about 2am this morning, about using the full path....Doh! But I wasn't going to get out of bed and try it.

    The none use of ../ and using / is a great tip, thanks.

    I use the full path for all pages - so guess I'm doing something right, one hell of a learning curve I'm on.

    Merry Crimbo & happy New Year.

    Ian

    P.S. Does this also mean the path for a CSS should be a full path at the moment I have ../../ when the file is in folders and sub folders.
     
    ian_ok, Dec 19, 2004 IP
  4. onestop

    onestop Well-Known Member

    Messages:
    534
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    138
    #4
    I can agree with this. But ian_ok is asking about including a menu with php. As we all know PHP is a server side language. So before a bot views the page at the client side, it's already executed and html is written. So when you try to add a menu with PHP include, as soon as you can reach the menu it doesn't matter which way you use.
    IMHO, the easiest way is either put the menu file in the root folder and use /menu.inc or use the full path. If a site has several menus in several subfolders, it may get tricky, and you may want to use the full paths (urls).
    good luck
     
    onestop, Dec 20, 2004 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #5
    Hi Onestop

    We're in agreement actually, check the example - it's for a gif.

    I was trying to talk about how the reference to the menu items are written when they the items are in other folders. Believe it or not but there are sites out there that point to links and images - found this at random http://www.harrison.gen.nz/jc.king/index.html I just didn't want Ian to make the same mistake.

    Sarah
     
    sarahk, Dec 20, 2004 IP
  6. Deliwasista

    Deliwasista Member

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #6
    Wow Sarah once again you save the day :) I cant believe I didnt think of absolute URLs.. using sons of suckerfish css menu as an include and was stumped as to what to do as soon as I left the main folder.. all of a sudden my links to home page etc werent working! Sometimes its the easiest solution .. doh!! Now I can go have dinner :) amazing storm over auckland tonight huh! :)
     
    Deliwasista, Jun 16, 2006 IP
    sarahk likes this.
  7. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #7
    Yeah - wild, wild night. My niece was flying to Wellington and was pretty freaked about what the landing would be like. Seems to have passed now though.

    Had the kids at swimming lessons in Mt Albert and the water was flooding INTO the pool complex, not out!
     
    sarahk, Jun 16, 2006 IP
  8. rajeev_seo

    rajeev_seo Peon

    Messages:
    211
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    when you a have that type of truble pls chick belowe link
    and find solution............
     
    rajeev_seo, Apr 24, 2011 IP
  9. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #9
    It will make it much easier for you with PHP includes to use BASEBATH variable.

    On any of your common pages, define a BASEBATH to be the basename for the website, then use that BASEBATH for the includes:

    define('BASEBATH', '/home/user/website/html');

    So no matter where you are on the server, you can always do:

    BASEBATH . '/includes/menu.php'

    This will help you avoid problems when moving files around and it is the standard on most MVC application (including Zend, codeIgniter).
     
    ThePHPMaster, Apr 24, 2011 IP
  10. victor-wd

    victor-wd Greenhorn

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #10
    Use this code to figure out your current path
    <?php echo getcwd() ?>
    PHP:
     
    victor-wd, Apr 24, 2011 IP