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.

How to properly code includes and which directory to place index.php

Discussion in 'Apache' started by av1040, Sep 26, 2016.

  1. #1
    I am trying to host an index.php page on a Linux Server running Apache. I am very familiar with hosting Html/Css websites but am not that knowledgeable about hosting php pages. Do I have to enclose php scripts within html tags and index.html page or can my home page be index.php? How the various directories and includes should be placed on the web page for the server to execute it properly?

    Many thanks!
    av1040, Sep 26, 2016 IP
  2. billzo

    billzo Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    PHP script must be enclosed in at least an opening tag <?php.

    Your index page can be index.php. In fact, most dynamic sites using PHP have index.php as their main page. If you want to process files with .html with the PHP engine, you will have to add a handler in your sever config or htaccess file.

    As for file includes, you can specify file paths relatively or absolutely. The choice is yours, really, to which you prefer. Some people are adamant about using absolute file paths and others prefer to use relative file paths in case they have to move their site to another server, assuming the scripts are all located under the /public_html folder.
    billzo, Sep 27, 2016 IP
  3. wordplucker

    wordplucker Well-Known Member

    Likes Received:
    Best Answers:
    Trophy Points:
    Do like I did long ago, cheat....

    I used a WordPress theme to learn things, structure, includes, etc....
    wordplucker, Sep 27, 2016 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Likes Received:
    Best Answers:
    Trophy Points:
    Basically, anything you can do in .html, you can do with .php. Also, if the file is a pure html-file, renaming it to php won't do anything, except you will then be running it through the php engine, which might make it a teeny, tiny bit slower. So you don't want to do that. You can perfectly fine mix .html and .php, but (usually) you CANNOT mix index.html and index.php - the server will normally default to the .html-file, which will mess up your system.

    As for includes, you can easily include anything that is within the web root folder. If your index.php is in the root folder of your site, having your script-files in a folder named script in the same directory, you'd include a file from that directory via include('script/filename.js') or include('/script/filename.js') (the extra beginning / will tell the include to look for the file at the root of the website, so it will work even if you try to include the file from inside some other subfolder on the site. You can also do includes via php either by doing include_once(), require(), or require_once().
    PoPSiCLe, Sep 30, 2016 IP