Jump to content

Protecting PHP Files!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Hey guys!

Okay so at the moment I'm half way through working on a huge web script, and I have files that are included in certain pages.

But I don't want these pages to be accessed individually, as they just display an error anyway.

So how would I create a script that displayed an error message if say getposts.php was accessed?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You could set a variable in index.php and check it with each page as the first step.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Bioshox

Bioshox

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 207 posts
Okay, so could I create a file named protect.php and within that have the code

<?php
define('protect', 1);
?>

And then another file named protectmsg.php with the code

<?php
if(!defined('protect')){
echo 'Denied.';
die;
}
?>

and if I don't want the file public accessible just include protectmsg.php and if I do want the script to be ran include protect.php?

#4
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Yea.. here I made a little tutorial months ago that explains Bioshox's method :

Protect Php Files - Trill Designs