How to restrict certain files from being open directly from the url / how to secure 'include' files

StackOverflow https://stackoverflow.com/questions/10261683

  •  02-06-2021
  •  | 
  •  

문제

I have various files which are included in one php page by the line: include'blahblah.php';

I am unable to figure out how to block direct access to these files from the address bar!

for example:

Anyone after looking at my source code can try to open the file 'blahblah.php' by typing in the address bar: http://www.mydomain.com/mydir/blahblah.php

How do i restrict people from doing so?

Thanks in Advance!

도움이 되었습니까?

해결책

the classic way of doing this is by using define and defined functions, in the main page you do some

define('pagescope', 'true');

And then on the included

if (!defined('pagescope')) die('nooooooo you cant');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top