Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

coder_uzb's avatar

auth check public folder php file?

Is it posible to use auth facade in a standard php file in public directory? I am using a third party plugin that scan the files in my file directory and display it as a clickable files in my ui. I want to authenticate the user logged in in my scan.php and scan only the files/folders that he/she created.

0 likes
10 replies
kvithalani's avatar

@coder_uzb I don't know it is possible or not but you may use another way like, You can store file name and user id in one table and from that you can do whatever you want.

coder_uzb's avatar

@kvithalani. Thank you for reply. But I before checked with this code.

require getcwd() . '/../../../../vendor/autoload.php';
    $app = require_once getcwd() . '/../../../../bootstrap/app.php';

    $kernel = $app->make('Illuminate\Contracts\Http\Kernel');

    $response = $kernel->handle(
        $request = Illuminate\Http\Request::capture()
    );

    $id = $app['encrypter']->decrypt($_COOKIE[$app['config']['session.cookie']]);
    $app['session']->driver()->setId($id);
    $app['session']->driver()->start();
    
    if(!$app['auth']->check()) return false;    
    return true;    

After Laravel 5.5 version, I have following error. unserialize(): Error at offset 0 of 40 bytes.

kvithalani's avatar

@coder_uzb Have you run this command after update the version:

php artisan key:generate

if no then please run this command may be your problem will solve....

coder_uzb's avatar

@kvithalani . I fixed problem. I added in App\Http\Middleware\EncryptCookies.php file this code

 protected static $serialize = true;
Nash's avatar

@CODER_UZB - Just be aware that re-enabling serialization can potentially become a security risk. See my previous post.

munazzil's avatar

Change as like below.

equire getcwd() . '/../../vendor/autoload.php';
    $app = require_once getcwd() . '/../../bootstrap/app.php';

Please or to participate in this conversation.