Jump to content


Photo
* * * * * 1 votes

Limit access to your php files


  • Please log in to reply
16 replies to this topic

#1 Joablen

Joablen

    Young Padawan

  • Members
  • Pip
  • 40 posts
  • Location:Chile

Posted 08 October 2006 - 03:48 PM

As you might be wondering what do i mean by direct access, by direct access i mean, to access directly to the file (example: www.yoursite.com/includes/file.php)...

Step 1
------------------------------------------
Now, for limiting direct access to those files you wanna protect from being access without being on your index for example, what we have to do is add a define on our index by adding this at the start of your code:
<?php
define("ON_OUR_SITE", true);
?>
where it says ON_OUR_SITE you can change it for whatever you want...


Step 2
------------------------------------------
after completing step 1, at the start of the code of each page you want to protect from being directly accessed you have to add something like this:
<?php
if (!defined("ON_OUR_SITE"))
{
   die ("Don't waste your time trying to access this file");
}
?>
where it says ON_OUR_SITE you have to change it to whatever you put on your index...


so that is all you have to do... that will say "Don't waste your time trying to access this file" to who ever tries to access your protect files directly, but it will show it's content on your index without any problem.
  • Josephkt likes this

#2 bblincoe

bblincoe

    Young Padawan

  • Members
  • Pip
  • 70 posts
  • Gender:Male
  • Location:New York
  • Interests:Guitar, Music, Computers, Lacrosse, Cross Country...and the list goes on.

Posted 14 October 2006 - 03:52 PM

Hey nice job stealing this tutorial.

http://www.webdesign...com/tutorial/45

Go steal some more why don't you. Loser.

#3 fedekiller

fedekiller

    Young Padawan

  • Members
  • Pip
  • 18 posts

Posted 14 October 2006 - 03:58 PM

well i made this tutorial before that one
http://php4all.org/n...rue-tid-90.html

everybody uses that, including phpbb i dont know if its a rip

#4 syphon

syphon

    Young Padawan

  • Members
  • Pip
  • 57 posts

Posted 14 October 2006 - 05:35 PM

Hey nice job stealing this tutorial.

http://www.webdesign...com/tutorial/45

Go steal some more why don't you. Loser.


That was very childish. For such a generic tutorial, there are bound to be copies. Just because your site has one version does not mean that others cannot. While there are copyrights on content, just because content appears to be duplicated does not mean it has been.

du

#5 cheerio

cheerio

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Gender:Male

Posted 14 October 2006 - 05:40 PM

Alot of people use this. All he's trying to do is help spread the idea. It's not like there's only 1 tutorial on making a stylish layout in photoshop is there? It's not ripped [Period]

#6 bblincoe

bblincoe

    Young Padawan

  • Members
  • Pip
  • 70 posts
  • Gender:Male
  • Location:New York
  • Interests:Guitar, Music, Computers, Lacrosse, Cross Country...and the list goes on.

Posted 14 October 2006 - 09:23 PM

My apologies then. If the intention was to just inform users of the concept, by all means go for it. It's not my site anyways, I just passed over it the other day. Once again, sorry about this misconception.

#7 cheerio

cheerio

    Young Padawan

  • Members
  • Pip
  • 246 posts
  • Gender:Male

Posted 14 October 2006 - 09:42 PM

My apologies then. If the intention was to just inform users of the concept, by all means go for it. It's not my site anyways, I just passed over it the other day. Once again, sorry about this misconception.

Everyone makes mistakes.

#8 Victor

Victor

    Young Padawan

  • Members
  • Pip
  • 11 posts
  • Gender:Male
  • Location:Ro, Bistrita

Posted 15 October 2006 - 04:59 AM

That's a method used by all programmers. Even IPB forums has it. Nice job spreading the idea!

#9 faulk

faulk

    Young Padawan

  • Members
  • Pip
  • 72 posts
  • Gender:Male
  • Location:Moosup, CT
  • Interests:Web design<br />Music<br />Audio engineering<br />Baseball (red sox!)<br />Snowboarding<br />Video production<br />Web app development

Posted 15 October 2006 - 09:04 PM

really cool idea I never even thought about it. When I'm done on "vacation" (no web coding for a few weeks hah) I am going to update my latest site include files with this method.

#10 Joablen

Joablen

    Young Padawan

  • Members
  • Pip
  • 40 posts
  • Location:Chile

Posted 15 October 2006 - 09:05 PM

really cool idea I never even thought about it. When I'm done on "vacation" (no web coding for a few weeks hah) I am going to update my latest site include files with this method.

great! it's good to hear that this tut is useful

#11 Alex_

Alex_

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 25 October 2006 - 11:53 PM

PLEASE HELP

I've made a test an does not work
In a folder I've created two files Index.php & SecondPage.php

<?php

// INDEX.PHP FILE

define("ON_OUR_SITE", true);
echo "<a href='SecondPage.php'>SecondPage.php</a>";

?>

<?php

// SECONDPAGE.PHP FILE

if (!defined("ON_OUR_SITE"))
{
   die ("Don't waste your time trying to access this file");
}

echo "Page Loaded !!!! ";

?>

Like Im accesing the secondpage by clicking a link and not by typing the address in the browser, think it have to work, but it seems "ON_OUR_SITE" is no passed and not defined to the SecondPage, Why?
What is the error?

Please Im new here and working PHP, can anyone help me

Thanks in advance

#12 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 26 October 2006 - 02:12 PM

For that to work index.php would have to be included in secondpage.php like so:
include "index.php";
above your conditional.

#13 Alex_

Alex_

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 26 October 2006 - 03:07 PM

Thanks Matthew it seems to work now, it returns me the page loaded when I click on the link, but it really does not work cause when I type the address on the browser it returns me the page loaded too.

Anyone could access the page directly.

Any idea?

<?php
define("ON_OUR_SITE", true);
echo "<a href='SecondPage.php'>SecondPage.php</a>";
?>
<?php

include "index.php";   // <------- ?????????????

if (!defined("ON_OUR_SITE"))
{
   die ("Don't waste your time trying to access this file");
}

echo "Page Loaded !!!! ";

?>


#14 Matthew.

Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 26 October 2006 - 04:53 PM

I would assume it has a link to secondpage.php on secondpage.php right? and that is not wantedi guess so you will need to put
define("ON_OUR_SITE", true);
in another file (seperate to index.php) and include it with secondpage.php and index.php

#15 d4o2

d4o2

    Young Padawan

  • Members
  • Pip
  • 20 posts

Posted 21 January 2007 - 01:27 PM

nice and simple.. thanks :D

#16 smart-coder

smart-coder

    Young Padawan

  • Members
  • Pip
  • 16 posts

Posted 29 January 2007 - 08:33 PM

Very interesting tutorial =), Its quite useful. But could'nt you just use .htaccess?

#17 Arutha

Arutha

    Young Padawan

  • Members
  • Pip
  • 144 posts
  • Gender:Male
  • Location:Southampton, England

Posted 19 February 2007 - 04:52 PM

That's a method used by all programmers. Even IPB forums has it. Nice job spreading the idea!


phpbb use it as well ;)

Very interesting tutorial =), Its quite useful. But could'nt you just use .htaccess?


the define command doesn't just need to be used for passwords, it could be used in multiple part forms to make sure the users done the previous part. It could be used to define a global variable even though sessions variables would be a better idea in that case.

Arutha




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users