php:work with sessions,everything is OK,but how to prohibit loading page that is always

Willbor

New member
a part of another page? You have part2.php page that is alsways used a part of globalpage.php.
I mean that at globalpage.php you have such a string: require_once('part2.php'). So part2.php puts its code into globalpage.php.
Unfortunately, you can just type localhost/part2.php and execute part2.php. Any ideas how to prohibit such use?
P.S. Sessions are OK, but that file is a part of globalpage.php for users with sessions and without sessions as well.
Thank you.
 
This is probably NOT standard practice.

One way you could force this is to set a variable in the page including or requiring the part2.php.

Then in part2.php you check to see if the variable is set with isset

so globalpage.php has:

$allowed = 1;

and part2.php has:

if(isset($allowed)) {
echo "Allowed";
} else {
echo "Denied"; //Or just don't display anything at all
}

All page requests to part2.php then wouldn't process the main code, while you still would in the require_once.
 
Back
Top