Is it better to check for a defined constant, check the url, or any other ways….
something like
if(!defined(INCLUDED))
of
if($_SERVER['REQUEST_URI'] == $_SERVER['PHP_SELF'])
What ways do you check if a file was accessed directly..also, is it important to prevent direct access to pages… (I figure a site should work in the way it was designed, so accessing directly would go against that, but) what are your thoughts
Defining a constant is probably the best way to go about it, without delving into tons of code… Just define a constant before your include line, and check to see if it’s defined in the included file…
main file
included_file.php
That way if they access the page, the constant won’t be defined and they’ll be redirected to wherever you want them to be.