PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
techkid
Forum Commoner
Posts: 54 Joined: Sat Sep 05, 2009 11:18 pm
Location: Maldives
Post
by techkid » Sat Oct 24, 2009 1:26 am
Suppose I've 2 Files. 1.php & 2.php
I don't want anybody to access 2.php directly from browser. Eg:
http://localhost/2.php but I want 2.php show up in 1.php like:
My question is how can I disable direct access using php not .htaccess
guosheng1987
Forum Newbie
Posts: 24 Joined: Thu Oct 15, 2009 3:03 am
Post
by guosheng1987 » Sat Oct 24, 2009 1:34 am
maybe you can wirte code like these
Code: Select all
1.php
<?php
$a = 5;
include ("2.php");
?>
2.php
<?php
if(empty($a))
redirect...
?>
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sat Oct 24, 2009 2:24 am
If you don't want 2.php accessible from the web then put it in a place that's not accessible from the web.
techkid
Forum Commoner
Posts: 54 Joined: Sat Sep 05, 2009 11:18 pm
Location: Maldives
Post
by techkid » Sat Oct 24, 2009 3:17 am
guosheng1987 wrote: maybe you can wirte code like these
Code: Select all
1.php
<?php
$a = 5;
include ("2.php");
?>
2.php
<?php
if(empty($a))
redirect...
?>
Any other possible ways?
Naeem
Forum Commoner
Posts: 31 Joined: Tue Jul 07, 2009 12:48 pm
Post
by Naeem » Sat Oct 24, 2009 3:42 am
You can also restrict access to your files by doing this:
Code: Select all
if (preg_match("/filename.php/", $_SERVER['SCRIPT_FILENAME'])) {
die("Restricted area get out of here");
exit;
}
change filename.php with your php file name
Hope this help.
Thanks.