php includes?

Discussion in 'PHP' started by problog, Dec 1, 2012.

  1. #1
    Hello does anyone know the php include code snippet I could use for a website?
     
    problog, Dec 1, 2012 IP
  2. AdamUK89

    AdamUK89 Active Member

    Messages:
    78
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    90
    #2
    Hi,

    If you search Google you'll find the codes easily :) but here are some of them

    Do you mean this code:
    Regards,
    Adam
     
    AdamUK89, Dec 1, 2012 IP
  3. problog

    problog Active Member

    Messages:
    76
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    81
    #3
    thank you very much!
     
    problog, Dec 1, 2012 IP
  4. yakuzaemme

    yakuzaemme Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Always use include("file") over include 'file'. Security matter and pathing matter.
     
    yakuzaemme, Dec 2, 2012 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    The ONLY difference between " " and ' ' is that " " costs extra processing to parse the variables within the quotes (whether there are any or not). Read the manual. You can write the same path, with the same security, using the same variables, either way.

    Always use ' ' when you can.
     
    Rukbat, Dec 2, 2012 IP
  6. madskillsmonk

    madskillsmonk Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    6
    #6
    You could also use require_once('file.php'). Require is different because if the require fails, the page will not load (it literally requires the file to load so if there is an error it wont load the page with the error)
     
    madskillsmonk, Dec 3, 2012 IP
  7. Maulik12

    Maulik12 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    <html>
    <body>

    <?php include 'header.php'; ?>
    <h1>Welcome to my home page!</h1>
    <p>Some text.</p>

    </body>
    </html>
    For More information visit my website to learn about php.
     
    Maulik12, Dec 4, 2012 IP
  8. Jekwueme

    Jekwueme Greenhorn

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #8
    using require_once() seems more efficient than includes.
     
    Jekwueme, Dec 4, 2012 IP
  9. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #9
    require_once() does an include(). If the file can't be included (it's not there, it can't be read, etc.), the script throws an error and stops. The difference between require() and require_once() is that if you have require() twice in one script, the included file will be included twice, with require_once() it will only be included the first time.

    As far as efficiency, they're all include(), but include_once(), require() and require_once() have additional code.
     
    Rukbat, Dec 4, 2012 IP