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

ahmadbadpey's avatar

use laravel Authentication in pure php scripts

I am working on a laravel App. a part of that is written pure php that is a html form and form submission script that stores data to Database.

Suppose form.php page is like :

<?php
    require('config.php');
?> 
<form action="process.php" method="post">
   <input type="text" name="username">
   <input type="submit" value="Send">
</form>

And process.php page is :

<?php
require ('config.php');
?> 
if (isset($_POST['submit_edu'])) {
        $username = trim($_POST['username']);
        // other codes to store data to DB
}

Now I want just Authenticated Users in main laravel app can access to those pages and send their info.

To access Auth laravel Object, I added below codes to beginning of config.php file that holds connection settings and required by those two page:

require __DIR__ . '/../../bootstrap/autoload.php';
    $app = require_once __DIR__ . '/../../bootstrap/app.php';
    $app->make('Illuminate\Contracts\Http\Kernel')->handle(Illuminate\Http\Request::capture());
    $kernel   = $app->make(Illuminate\Contracts\Http\Kernel::class);
    $response = $kernel->handle(
        $request = Illuminate\Http\Request::capture()
    );

    if (!Auth::check()) {
        exit('Only authorized Users can access to this page');
    }

As you can see if an unAuthorized user want to pages encounters an error.

Now when an Authenticated user want to open form.php page (in face via GET method) Auth::check() works correctly but when clicks on submit form button and data sent to process.php (viaPOST` method) , it always returns false.

While if I open same process.php via GET method Auth::check() works correctly again.

Means in this case Auth::check() can not work properly.

What is problem in your idea. can anyone help me to solve this problem?

0 likes
1 reply
Indemnity83's avatar

I don't understand why you're using plain PHP for this? How is this any different functionally than the boilerplate you get with php artisan make:auth?

Please or to participate in this conversation.