2013-11-20 58 views
0

基本上,我目前正在开发某种形式的框架,它将有一个主要的索引文件来控制显示的页面,然后我会include文件基于使用.htaccess重写的URL,因此我的.htaccess看起来像这样。在PHP中包含一个包含文件

Options +FollowSymlinks -MultiViews 

AddType "text/html; charset=UTF-8" html 
AddType "text/plain; charset=UTF-8" txt 

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase/

    # if file not exists 
    RewriteCond %{REQUEST_FILENAME} !-f 

    # if dir not exists  
    RewriteCond %{REQUEST_FILENAME} !-d 

    # avoid 404s of missing assets in our script 
    RewriteCond %{REQUEST_URI} !^.*\.(jpe?g|png|gif|css|js)$ [NC] 

    # core framework url rewriting 
    RewriteRule^index.php [L] 
<IfModule mod_rewrite.c> 

虽然记住,我有这行RewriteRule^index.php [L]我然后使用下列保持我的index.php

define("PAGES", $_SERVER['DOCUMENT_ROOT']."/pages"); 

$uri = explode("/",substr($_SERVER['REQUEST_URI'],1)); 
if((isset($uri[0])) && ($uri[0]!="")) {$page = $uri[0];} else {$page = "login";} 

if(is_file(PAGES."/$page/$page.php")) { 
    include(PAGES."/$page/$page.php"); 
} else { 
    include(PAGES."/error_pages/404.php"); 
} 

这会被视为足够安全?还是会提供某种形式的漏洞利用的能力?

+0

这似乎很好很多CMS框架像WP运营商在类似的模式。 – anubhava

+0

感谢您的评论,最好让其他开发者的观点 – Curtis

回答

0

更好的解决方案是使用PHP> = 5.3的名称空间和自动加载功能。您的解决方案必须安全,直到用户无法在DOCUMENT_ROOT中创建自己的文件,并且应该避免将文件包含在DOCUMENT_ROOT之外。