authentication - PHP: Use PHP to authenticate with .htaccess when uploading to a subfolder of the protected folder -


i'm trying upload files subfolder of protected folder. here hierarchy looks like:

/basefolder(.htaccess)/tool/script.php

/basefolder(.htaccess)/tool/uploadhandler.php

/basefolder(.htaccess)/tool/files/here(subfolder)/

the simple .htaccess file basefolder is:

authuserfile "/path/" authtype basic authname "admin dashboard" require valid-user 

the script sends data typical php upload handler attempts save file in subfolder. when code gets stage browser prompts me user/pass again.

is there way authenticate using php don't prompted password every time?

exempt upload.php file http password protection , use sessions or cookie set user allowed upload.

for example, in php file upload form:

session_start();  $_session['can_upload'] = true; // set if user access upload form // page; sessions preferable cookies since set cookie named // "is_allowed" "1"—you have use kind of token validation // if used cookie 

and in php file handling file uploads,

session_start();  if (! isset($_session['can_upload'])) {   header("403 forbidden");   echo("you not authorized!");   die(); }  // user ok, put upload logic here 

Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -