PHP include file extensions?

后端 未结 3 1448
深忆病人
深忆病人 2021-01-06 03:35

For required/included files in PHP, is it better to use .inc extensions vs .inc.php vs .php extensions?

3条回答
  •  清歌不尽
    2021-01-06 04:05

    Apache can sometimes (due to bugs or severe crashes) serve .php files as text (happend to me a few times on shared hosting).... I think you can use any extension you want as long as you don't store your files in a public folder.

    Let's say your site is in /home/user/public_html/

    create another folder /home/user/lib_php/

    have the files:



    (1) .../lib_php/one.class.php with

    class one { 
    //...
    }
    



    (2) .../lib_php/two.function.php with

    function two() { 
    //...
    }
    

    and you have the main index.php in /public_html

    
    
    

    $x=a; $b=two($x); $c=new one; //etc..

    or

     
    

    This way you are taking every precaution the files are not reachable directly but can be used by your scripts...

提交回复
热议问题