开发者

dont print out buffered content

php : view.php

<h1>hello world</h1>

php: index.php

require('view.php');

if both files are on root mysite.com

if I access mysite.com/index.php I should get 'hello world'

if I access mysite.com/view.php I should get Nothing displayed.

I was looking for some .HTACCESS method but any other suggestions are welcomed :)

Conclusion: wish the user to not be able to see the view plain text, and only allow the required or get_file_开发者_JAVA百科contents() to read the files. So read the file only within server.


The best way to handle this is to have your include files that are never intended to be accessed outside the web root, where they can never be accessed via a browser.

i.e. your file structure would be:

www/index.php
includes/view.php

You can set PHP's include_path to include the includes/ directory so your includes don't need to have a path explicitly in them, too.


Don't print your output. Make some variable (for example:$tmp) with output data and print it in index.php


there is .htaccess stuff you can do

<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>

this isnt going to be exactly what you want, but i think if you combine this with ceejayoz's answer, it should work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜