Jump to content

avoinding direct access


etrader

Recommended Posts

I have a php form for uploading file as the action sends to upload.php. How I can avoid any kind of direct access to upload.php? I want to kill the php process at the first line without performing the remaining code (it is very critical for me as I have a counter), except calls coming from form.php.

Link to comment
https://forums.phpfreaks.com/topic/236880-avoinding-direct-access/
Share on other sites

If you have named your submit button in your form then check for the $_POST['submit_button_name'] variable in exists in upload.php, eg

if(isset($_POST['submit']))
{
     // add the code for uploading the images here
}
else
{
    // display error or redirect back to form.php here
}

Sorry, I didn't play close enough attention that you are going through an html form.

However, post variables and headers can be spoofed, so while either will work, they are not 100% reliable.

If you want to be 100% sure, you would need to use a server side cache such as APC.

Or stepping outside of php, I think the best solution is defining a rule in .htaccess.

Is the upload from being drawn with php via a templating system or anything?  If so you could include a randomly generated string with the login form, which is stored in a database, then checked for in upload.php.  That would make it so that any submission would have to come from you upload form. 

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.