Jump to content

[SOLVED] Question about validation


proggR

Recommended Posts

Is there anyway to tell where exactly a file is being accessed from?

I want to see if I can block access directly to certain files through the URL but allow that file to be accessed and used by certain pages within my site. Is there anyway to see where its being accessed from so I can use some sort of if/else block to prevent anyone from directly accessing the file either entirely or without authorization?

 

Link to comment
https://forums.phpfreaks.com/topic/114447-solved-question-about-validation/
Share on other sites

You can check if it is being accessed directly by using something like:

 

I am assuming you are including pages like ?page=folder/page.php or something like that.

So in the index.php page that has this include script, above the include scripts you would have a variable like so:

 

$direct_linking = false; //we set it to false, because they are NOT direct linking

 

Then in your files that you include, so in page.php you would have this:

 

if($direct_linking || $direct_linking == ""){ //they are viewing this file directly!
die("You do not have permission to view this file.");
}else{
//show page
}

 

There would be more ways to do this though. :)

Thanks :)

Is there anyway to do that on a folder level? Like deny access to the entire folder in the same way, instead of file by file? Luckily I haven't started posting content so its not a HUGE deal but if I could get around that it'd be great. Especially since some of the files I'm talking about will be text files and won't have scripting.

Yah I still have to look into .htaccess because I do have a few files that I want password protected and hidden. I'll look into what it can do for folders too. Thanks :)

What is cPanel btw? No doubt I could google it and find a plethora of information but I've heard of it a lot lately and was wondering if someone could sum it up.

 

*edit* nvm I looked it up. It looks pretty sweet. I might look into that, but I'll look into .htaccess either way.

Thanks :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.