Can JEXEC be used on any php script or its for Joomla only

Most of Joomla scripts starts with

 defined('_JEXEC') or die('Restricted access');

From joomla site i came to know this line makes it more secure from hackers so I want to know if this can be used on any php files or it supports only on Joomla Cms?

What is JEXEC actually for?

The variable that’s defined is for Joomla only, although you can use the same concept in your own script.


define("ALLOW_ACCESS", true);

defined("ALLOW_ACCESS") or die("You can't access this page");

<html><body>Hello world!</body></html>


defined("ALLOW_ACCESS") or die("You can't access this page");

<html><body>Hello world!</body></html>

This line just requires that a predefined constant (for example, ‘_JEXEC’) must be set in order to use the script.

You can do it to secure your include files by having your normal page define the constant, and the included file check for it.

JEXEC is just a name. It could be ‘fuzzytutu’ as far as PHP’s concerned, as long as something else has defined that constant before that point.