0

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');
3
Contributors
3
Replies
7
Views
6 Years
Discussion Span
Last Post by hielo
0

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!');
...
?>

Edited by hielo: n/a

0

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 ?

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.