Jump to content


Photo

make file readable only when it is included or required else display error404

display url 404 error404 url

  • Please log in to reply
1 reply to this topic

#1 Regex

Regex

    Newbie

  • New Members
  • Pip
  • 2 posts

Posted 19 May 2013 - 12:59 PM

I how a problem that if someone goes in myurl.../content.php he can see my content.php file but I would like that it could bee seen only  when I include that in myurl.../index.php. How it could be done that if someone goes to myurl.../index.php/content.php he is redirected to error 404 but if I include that file somewhere then it does not redirecting.

 

 



#2 kicken

kicken

    Wiser? Not exactly.

  • Gurus
  • 2,703 posts
  • LocationBonita, FL

Posted 19 May 2013 - 01:24 PM

Have index.php define a constant, and inside content.php check if that constant has been defined. Of not, redirect.

Index
<?php
define('IN_INDEX_PHP', true);
include('content.php');
Content
<?php 
if (!defined('IN_INDEX_PHP')){
   header('Location: index.php');
   exit;
}

Recycle your old CD's, don't trash them!
Did I help you out?  Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com