473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Prevent loading of php pages

I have a website consisting of php segments.

Example
page1.html calls in code from seg1.php and seg2.php

If the user goes directly to www.mydomain.com/seg1.php they see everything
visible to a browser on that page.

Can I prevent users from loading individual php segments. The only time that
seg1.php should be visible is in its original context on page1.html

Garry Jones
Sweden

Apr 26 '06 #1
7 3596
On Wed, 26 Apr 2006 23:53:13 +0200, "Garry Jones"
<ga*********@morack.se> wrote:
I have a website consisting of php segments.

Example
page1.html calls in code from seg1.php and seg2.php

If the user goes directly to www.mydomain.com/seg1.php they see everything
visible to a browser on that page.

Can I prevent users from loading individual php segments. The only time that
seg1.php should be visible is in its original context on page1.html


Would anyone ever guess that files by that name existed?
Call them seg1_56rt568.php and seg2_56rt569.php

--
Regards, Paul Herber, Sandrila Ltd. http://www.pherber.com/
Electronics for Visio http://www.electronics.sandrila.co.uk/
Apr 26 '06 #2
Something like this at the top of the include file would work:

count(get_included_files()) > 1 or die();

But really, including files in lieu of calling functions is kind of
lame.

Apr 26 '06 #3
>I have a website consisting of php segments.

Example
page1.html calls in code from seg1.php and seg2.php

If the user goes directly to www.mydomain.com/seg1.php they see everything
visible to a browser on that page.

Can I prevent users from loading individual php segments. The only time
that seg1.php should be visible is in its original context on page1.html


The way Joomla and Mambo handle this is as follows:

In page1.php (surely you meant .php, not .html?) you do this right at the
top:

define( 'MAIN_PAGE_LOADED', TRUE );

Then, in "seg1" and "seg2" you do this, again right at the top:

defined( 'MAIN_PAGE_LOADED' ) or die ( 'This page is restricted' );

So, you prevent 'seg1' and 'seg2' from being directly loaded by the user.
They can only be used as include files in 'page1'.

Seems like a simple and effective solution.

-Dana

Apr 27 '06 #4
Garry Jones wrote:
I have a website consisting of php segments.

Example
page1.html calls in code from seg1.php and seg2.php

If the user goes directly to www.mydomain.com/seg1.php they see everything
visible to a browser on that page.

Can I prevent users from loading individual php segments. The only time that
seg1.php should be visible is in its original context on page1.html

Garry Jones
Sweden


Simply put them outside of your DOCUMENT_ROOT where they can't be accessed
directly by a browser.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 27 '06 #5
"Jerry Stuckle" <js*******@attglobal.net> skrev i meddelandet
news:eI********************@comcast.com...
Simply put them outside of your DOCUMENT_ROOT where they can't be accessed
directly by a browser.


How do I do that?

(Excuse the newbie follow up question. I searched around in Google but can't
quite grasp this).

Thanks to you and all others who answer my questions here, I am enlightened.

Garry Jones
Sweden

Apr 27 '06 #6
"Dana Cartwright" <da******@weavemaker.com> skrev i meddelandet
news:nR****************@twister.nyroc.rr.com...
defined( 'MAIN_PAGE_LOADED' ) or die ( 'This page is restricted' );


Thanks for your answer.

Instead of 'This page is restricted' can I have a weblink for them to click
or even an auto redirect to the my index page?

Garry Jones
Sweden
Apr 27 '06 #7
Garry Jones wrote:
"Jerry Stuckle" <js*******@attglobal.net> skrev i meddelandet
news:eI********************@comcast.com...

Simply put them outside of your DOCUMENT_ROOT where they can't be accessed
directly by a browser.

How do I do that?

(Excuse the newbie follow up question. I searched around in Google but can't
quite grasp this).

Thanks to you and all others who answer my questions here, I am enlightened.

Garry Jones
Sweden


The document root id the root directory of your website. But it is not the root
directory of your machine. For instance, your document root might be
"/var/www/website1/html".

When you upload them, put them in a directory below the root of your website,
i.e. "/var/www/website1/myfiles". You can then include this page in your
other PHP pages with something like (assuming Apache):

include($_SERVER['DOCUMENT_ROOT'] . '/../myfiles/my.inc.php');

Anyone accessing a page through http protocol can only access those files in
your web root. But PHP accesses the file system directly, so it can access any
file on the system (assuming the appropriate permissions are set).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Apr 27 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob Tweed | last post by:
I have a customer who is having problems when their Windows 2000/IIS/PHP-based system begins to experience a level of loading that isn't, in my view, unreasonably high. I'm wondering what others...
25
by: Dave Turner | last post by:
I know that its impossible to completely prevent somebody from ripping a site (or cracking software) if that person has the skills and the time/patience, but there are tricks that can be employed...
4
by: seans | last post by:
Hi, Is there some way from preventing the JavaScript code in a document loaded into an iframe from executing? I don't have access to the pages being loaded into the i-frame so I can't modify...
5
by: Manish Jain | last post by:
Environment: Windows 2000 Server (SP4), ASP.Net/C# (Framework 1.1) Hardware: PIII @ 700 MHz, 512 MB RAM ----------------------------------------------------------------------------...
4
by: KJS | last post by:
Help, I'm not sure what exactly is happening but I can say this, classic asp pages are not loading on my local dev box. They use to work! Since then I have installed .NET 1.1 Studio (that is...
6
by: ImOk | last post by:
I am using Windows IIS with PHP5 CGI. When I want to use an extension in PHP5 under Windows I enable the extension line in PHP.INI. (e.g. extension=php_sqlite.dll). Does PHP load all the...
3
by: Phil | last post by:
Jerry posed some good ideas, a while back, on website a security issue that comes up often. Gary Jones was asking how to keep users from directly accessing php pages, out of sequence. Jerry...
0
by: vinayakk | last post by:
Hello webies, I have a problem with loading html pages in frameset. I am using location.href to load html pages one by one upon the user request and these pages in turn load flash files. When one...
6
by: Shigun | last post by:
On a website I am working on I am trying to load another page into a div on the the page the user does his work from. What I have works correctly in FireFox, but not in IE. I've rummaged Google for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.