How To Stop Direct Access To PHP File

 1. index.php

<?php define('SECURE_PAGE', true); include 'header.php';
//all data of index page
?>

2.header.php (Show error that Direct File Access Prohibited)

<?php if (!defined('SECURE_PAGE')) { die('<h1>Direct File Access Prohibited</h1>'); } ?>

2.header.php (Redirect to homepage)

<?php
if (!defined('SECURE_PAGE')) { header('Location: ./'); }
?>

Post a Comment

0 Comments