K
K
Koal Koalich2017-08-07 12:36:05
1C-Bitrix
Koal Koalich, 2017-08-07 12:36:05

How to correctly check and prevent the file from executing during a direct call?

Let's say I put function files in the libs folder and include them in several pages. But how to check that the access to these files was direct (for example, site.ru/libs/functions.php) and prohibit their execution outside the connection in other files?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lander, 2017-08-07
@tmman

Well, the usual way is to define a variable of type $access = true in index, and check in the included file:
if (!isset($access) || !$access) exit();

I
Ilya, 2017-08-07
@rpsv

Deny access to the libs folder (if access is needed only from within).
You need to throw .htaccess into libs:
deny from all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question