TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-24-2008, 05:16 AM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default how to block a user from viewing a specific page

im wondering how i would be able to program this.

say i have pages that dont have anything on it but has backend code.

how do i block people from typing that page into the url and view it?
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 04-24-2008, 06:15 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

a) Don't put it in your document root. Have scripts call it from a different location.

b) If you have an Apache server, deny it with .htaccess or in your httpd.conf

c) make sure the file extension is .php so that the code will be parsed and unviewable in the browser.

d) put up a stop sign.

e) password protect the directory (view .htpasswd or whatever your server uses)

f) disable indexes.

g) if you have a user authentication system and the script is an administration script of some sort, check for administrative authorization or kill the script if it's not found.

It all depends on the specifics of what you're doing, and why you're doing it.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-24-2008, 10:52 AM   #3 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

PHP Code:
// Define something in your main files which are accessable (like index.php)
define('SYSPATH''path_or_something');

// Now put in every include file a check if the main file is loaded
defined('SYSPATH') or die('No direct script access.'); 
You can define whatever you like, this is just how Kohana does the trick :)
maZtah is offline  
Reply With Quote
Old 04-24-2008, 01:53 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

At the beginning of every file, put something like
PHP Code:
define('IN_SCRIPT',true); 
And at the beginning of every source file that you dont want directly accessed.
PHP Code:
if(!IN_SCRIPT){die("No Direct Access");} 
__________________

Village Idiot is offline  
Reply With Quote
Old 04-24-2008, 02:05 PM   #5 (permalink)
The Contributor
 
Evulness's Avatar
 
Join Date: Apr 2008
Location: Tampa, FL
Posts: 65
Thanks: 6
Evulness is on a distinguished road
Default

i've been using...

Code:
//on index page
define ('SysFile', '1');

//on every page that is to only be viewed if accessed via index.php before EVERYTHING...
if (SysFile != '1')
{
die ('Attempting to access Restricted file!');
}
that will check if SysFile = 1, if SysFile isn't defined, script dies.
You could do a header('Location: h*ttp://site.com/index.php instead of die()

something i just thought of... writing a little script to log attempts to access restricted files. http_refferer, ip, time , etc... so you can see when, who... i'll post something about this later, cause i just had some crazy ideas heh
__________________
"Knowledge is power. Abuse it."~Evulness
My portfolio: www.evularts.com

Last edited by Evulness : 04-24-2008 at 02:08 PM. Reason: link went wrong
Send a message via AIM to Evulness
Evulness is offline  
Reply With Quote
Old 04-25-2008, 01:31 AM   #6 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

on the top of my page i put

define('accesslevel', true);
if(!accesslevel) { header("Location: index.php");


and i loaded the page and nothing happend.
what am i missing

(well obviously it wont work so what else do i need to put)
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 04-25-2008, 01:52 AM   #7 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Well, if those are both on the same page, then ACCESSLEVEL is true, and therefore the if statement doesn't execute.

Just a note for security purposes, if you want to make sure that nobody is going to view your page, you may want to add exit() or die() after the header() statement. Good ole lynx doesn't care about your header's if it doesn't want to.
-m
delayedinsanity is offline  
Reply With Quote
Old 04-25-2008, 02:02 AM   #8 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

this worked for me

define('noaccess', false);
if(!noaccess) { header("Location: login.php"); }
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 04-25-2008, 02:20 AM   #9 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

PHP Code:
if (!NOACCESS) {
    
header("Location: http://www.yoursite.com/login.php");
    die(
"aaaAAAaaaUUUuuuUuurrgh.");

delayedinsanity is offline  
Reply With Quote
Old 04-25-2008, 03:02 AM   #10 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Also don't forget the
PHP Code:
if(!defined('NOACCESS'))
{
//

__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:10 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design