How do I create a constant No direct script access allowed.
As is the Joomla CMS.?

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Recommended Answers

All 3 Replies

Let's say that page1.php includes page2.php, but you want page2.php to NOT be accessed directly. So on page1.php you define the constant:

<?php
//page1.php
define('RESTRICTED',1);
include('page2.php');
...
?>

Then in page 2 you simple check to see if the constant is defined:

<?php
//page2.php
if(!defined('RESTRICTED'))exit('No direct script access allowed!');
...
?>
Member Avatar for P0lT10n

Let's say that page1.php includes page2.php, but you want page2.php to NOT be accessed directly. So on page1.php you define the constant:

<?php
//page1.php
define('RESTRICTED',1);
include('page2.php');
...
?>

Then in page 2 you simple check to see if the constant is defined:

<?php
//page2.php
if(!defined('RESTRICTED'))exit('No direct script access allowed!');
...
?>

But if you do a redirect with header

header("Location: page1.php")

Will you see something or it will automatically refresh to page1.php ??? I never used this, but if i am right, i would be another way, no ?

Will you see something or it will automatically refresh to page1.php ??? I never used this, but if i am right, i would be another way, no ?

Yes, BUT there would be one "major" requirement. No output may be sent do the browser before the header() call.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.