2

I have two PHP Pages, an index.php and a content.php. I am using the code include("content.php"); on the index.php file. Is it possible to check whether the user is on index.php or did he go straight to content.php ?

Basically what I want to do is display content.php on index.php but if the user went directly to content.php then I don't want the script to do anything.

Matt
  • 1,087
  • 1
  • 12
  • 28

2 Answers2

1

Add this to the page that you want to only be included

<?php
if(!defined('MyConst')) {
    die('Direct access not permitted');
}
?>

then on the pages that include it add

<?php
    define('MyConst', TRUE);
?>
zagrippa
  • 21
  • 2
1

index.php

$chk = 1
include("content.php");

content.php

if ($chk < 1){
  include('index.php');
  exit;
}
Misunderstood
  • 5,534
  • 1
  • 18
  • 25