Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
804 views
in Technique[技术] by (71.8m points)

security - placing php script outside website root

how would i a)include a php script that is outside the web root (would it really be just a simple ../file.php), b)post form data to a php script outside the web root. I'm led to believe this is a corner stone to php security.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

including a script that's outside the webroot is easy : you'll do the same way as you're doing for a script that's under the webroot :

include '../myscript.php';
include '../library/myscript.php';
include dirname(__FILE__) . '/../library/myscript.php';

The one you prefer ;-)
I would go for the last one, personnaly, though.


Posting to a script that's outside the webroot is not possible : that script cannot be served by Apache (Apache only serves what's inside the web-root).

So, that script cannot be accessed via HTTP ; which means it cannot be accessed from/by the browser.

But if you are posting to a PHP script that's inside the webroot, and that script includes another one that is outside the webroot, then the code in that second file will be executed as the first script. Which means it'll have access to the $_POST data -- the data typed in the form.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...