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.

Using PHP Include

Discussion in 'PHP' started by Crusader, Sep 11, 2005.

  1. #1
    When using the PHP include function to include for example, the navigation code for a html page, would it be best to save the code in a html or normal txt file:

    E.g

    <?php
    include("menu.txt");
    ?>

    or

    <?php
    include("menu.html");
    ?>

    Would there be any difference?
     
    Crusader, Sep 11, 2005 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    No difference as far as PHP is concerned. It's all the same. It just grabs the contents and deposits it right there and then. I always name them .inc - on most servers you can't call .inc in the browser directly so you don;t get any indexed gibberish.
     
    T0PS3O, Sep 11, 2005 IP
  3. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah, ok. That's actually a great idea. I was worried about search engines indexing one of these files. So that'll put a stop to it. Thanx!
     
    Crusader, Sep 11, 2005 IP
  4. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Is there any other drawbacks or bonusses (except for making the site easier to manage) to using the include in this way? Eg. Does it affect search engines in any way?
     
    Crusader, Sep 11, 2005 IP
  5. alext

    alext Active Member

    Messages:
    406
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    68
    #5
    Since the file gets included before anything is published, no one, including a search engine would ever know a file was included. So it will make no difference at all.
     
    alext, Sep 11, 2005 IP
  6. Crusader

    Crusader Peon

    Messages:
    1,735
    Likes Received:
    104
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks. I don't know why I didn't start using it MUCH sooner. It's great!
     
    Crusader, Sep 11, 2005 IP
  7. pcdoc

    pcdoc Active Member

    Messages:
    690
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    70
    #7
    Since the file gets included before anything is published, no one, including a search engine would ever know a file was included. So it will make no difference at all.

    Exactly, I use it on most all my sites for footers and adsense code.
     
    pcdoc, Sep 11, 2005 IP
  8. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #8
    You can however have documents you really don't want indexed, but will be included in other webpages (like the building blocks - footers and headers) stored in other parts of your webspace.

    See my article on Secure File Locations - any questions? ask away and I'll answer them as best I can

    Sarah
     
    sarahk, Sep 12, 2005 IP
  9. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #9
    NEVER NEVER NEVER name it txt... always a PHP extension. You don't want visitors doing directory scans and then pulling up your code in a txt file. Sarahk's advice is right on the money.. if it is extra-sensitive, store it above the public_html branch so it is never accessible except to your own scripts.
     
    TheHoff, Sep 12, 2005 IP
  10. michele

    michele Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Anything with database usernames and passwords, for example, should always be outside/above the web DocumentRoot directory ... if they were inside the web directory and had a .txt extension, anyone could read them.

    Using a .php extension is better, because these files at least get parsed before they're sent, but they're not ideal for sensitive info because it is possible that someone misconfigures the server one day and .php get sent through unparsed ... unlikely but it has happened!
     
    michele, Sep 20, 2005 IP