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

utmsandeep's avatar

Using Auth::user(); in core php

I'm working on a project , the problem is that some part of the project is made in laravel and some part in core php . Now i want to perform authentication through Auth Facade for my project . Some files are being accessed through routes and some files which are in core php are being accessed directly . so the files which are being accessed through routes Auth is working perfect But what to do for core php files , i don't want to use $_SESSION. Please suggest me a way to use Auth in my core php files.

0 likes
5 replies
munazzil's avatar

Use as like below and in header you can redirect to any page.

<?php
session_start();
if (!isset($_SESSION['username'] )){
header('location:/book/index.php');
}
 ?>
utmsandeep's avatar

I don't want to use $_SESSION any where in my project for Authentication purpose.

munazzil's avatar

Use as like below '\Auth::user()'

<?php if (!isset(\Auth::user() )){ header('location:/book/index.php'); } ?>

utmsandeep's avatar

my files do not know Auth::user(); this is the problem.

bestmomo's avatar

I made something with Laravel 5.2 to get Laravel app from core PHP :

require getcwd() . '/../../../../bootstrap/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();

Dont know if it works with recent Laravel version but it's a way. You can use $app['auth'] for example.

Please or to participate in this conversation.