Is there a way to run multiple script before loading starts with php?

Can you run multiple script before file upload starts in php? For example, I send POST to upload.php, and in this file I want to check their $ _SESSION first, before I start spending bandwidth and uploading files to them on my server. I am using php 5.2.11 on nginx.

<?php if ($_SESSION['admin'] == 'YES') { // do upload here } else { exit; } ?> 
+4
source share
3 answers

Not. The request does not reach the PHP engine until the file is uploaded.

+2
source

No, because loading is part of the request and is executed before PHP even starts playing.

Around this, there may be a method using the technique of those PHP / Perl-based boot loaders that somehow connect to the boot process, but then it may not be either. Especially if you are using a different web server.

I would do an Ajax-based quick check for the correct session and bind it to the submit event of the form you are loading the file into. This may take half a second, but is completely unobtrusive to the user.

+1
source

You can make an ajax call on the page the form is submitted to to check the status of your session before allowing the form to be submitted.

0
source

Source: https://habr.com/ru/post/1305046/


All Articles