laravel local.ERROR: Undefined index: HTTP_HOST in AppServiceProvider.php - laravel

i use laravel and have multiple domain like example.com , example.co , example.org
also i use api and laravel task scaduleing to update post view in day , week , month
using below code to make dl sever domain according user domain entered
AppServiceProvider.php
public function boot()
{
Schema::defaultStringLength(191);
$dl_server = 'http://dl.' . str_replace('www.', '',$_SERVER['HTTP_HOST']) . '/';
View::share('dl_server' , $dl_server);
}
but in laravel log file i got many error
[2020-10-12 00:00:01] local.ERROR: Undefined index: HTTP_HOST {"exception":"[object] (ErrorException(code: 0): Undefined index: HTTP_HOST at /home2/exampleco/domains/example.com/example/app/Providers/AppServiceProvider.php:30)
[stacktrace]
#0 /home2/exampleco/domains/example.com/example/app/Providers/AppServiceProvider.php(30): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Undefined index...', '/home2/exampleco...', 30, Array)
#1 [internal function]: App\\Providers\\AppServiceProvider->boot()
#2 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#3 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Support/helpers.php(522): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#4 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): value(Object(Closure))
#5 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#6 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Container/Container.php(591): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#7 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(828): Illuminate\\Container\\Container->call(Array)
#8 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(811): Illuminate\\Foundation\\Application->bootProvider(Object(App\\Providers\\AppServiceProvider))
#9 [internal function]: Illuminate\\Foundation\\Application->Illuminate\\Foundation\\{closure}(Object(App\\Providers\\AppServiceProvider), 23)
#10 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(812): array_walk(Array, Object(Closure))
#11 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#12 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(211): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#13 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(320): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#14 /home2/exampleco/domains/example.com/example/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#15 /home2/exampleco/domains/example.com/example/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#16 {main}
"}
and this error repeat every minute [2020-10-12 00:00:01] , [2020-10-12 00:01:01] , ...
whats the problem ?

$_SERVER['HTTP_HOST'] only available if app called from HTTP Request, the error log say it's called from console (eg: task scheduling) so the variable is not exists.
Simply put variable checking using empty() or isset(), or check if not running in console with this sample code:
if (!\App::runningInConsole()) {
Log::debug("AppServiceProvider::boot ".$_SERVER['HTTP_HOST']);
}

Related

Laravel Multi-Tenancy - Installation Error

I am trying to pull spatie/laravel-multitenancy into my Laravel application
Installing on Laravel 7 running PHP 7.4
php artisan --version
# Laravel Framework 7.30.4
php -v
# PHP 7.4.13 (cli)
The installation
composer update
composer require "spatie/laravel-multitenancy:^1.0"
Throws up this error at the end
In QueueManager.php line 156:
Trying to access array offset on value of type null
Error Log
[2021-09-01 11:54:41] production.ERROR: Trying to access array offset on value of type null {"exception":"[object] (ErrorException(code: 0): Trying to access array offset on value of type null at D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\QueueManager.php:156)
[stacktrace]
#0 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\QueueManager.php(156): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(8, 'Trying to acces...', 'D:\\application...', 156, Array)
#1 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\QueueManager.php(138): Illuminate\\Queue\\QueueManager->resolve('file')
#2 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\QueueManager.php(258): Illuminate\\Queue\\QueueManager->connection()
#3 D:\\application\\vendor\\spatie\\laravel-multitenancy\\src\\Actions\\MakeQueueTenantAwareAction.php(34): Illuminate\\Queue\\QueueManager->__call('createPayloadUs...', Array)
#4 D:\\application\\vendor\\spatie\\laravel-multitenancy\\src\\Actions\\MakeQueueTenantAwareAction.php(18): Spatie\\Multitenancy\\Actions\\MakeQueueTenantAwareAction->listenForJobsBeingQueued()
#5 D:\\application\\vendor\\spatie\\laravel-multitenancy\\src\\MultitenancyServiceProvider.php(72): Spatie\\Multitenancy\\Actions\\MakeQueueTenantAwareAction->execute()
#6 D:\\application\\vendor\\spatie\\laravel-multitenancy\\src\\MultitenancyServiceProvider.php(33): Spatie\\Multitenancy\\MultitenancyServiceProvider->configureQueue()
#7 [internal function]: Spatie\\Multitenancy\\MultitenancyServiceProvider->boot()
#8 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(37): call_user_func_array(Array, Array)
#9 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#10 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#11 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(39): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#12 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(596): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#13 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(867): Illuminate\\Container\\Container->call(Array)
#14 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(850): Illuminate\\Foundation\\Application->bootProvider(Object(Spatie\\Multitenancy\\MultitenancyServiceProvider))
#15 [internal function]: Illuminate\\Foundation\\Application->Illuminate\\Foundation\\{closure}(Object(Spatie\\Multitenancy\\MultitenancyServiceProvider), 23)
#16 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(851): array_walk(Array, Object(Closure))
#17 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Bootstrap\\BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#18 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Application.php(230): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#19 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(310): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#20 D:\\application\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(127): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#21 D:\\application\\artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 {main}
"}
Any ideas why this is happening?

Laravel: using count in the where clause throwing error

I am working on a Laravel project. I am trying to write an Eloquent where I need to use raw where clause for COUNT.
This is my query.
$eligibleReceivers = ReceiverDevice::havingRaw('COUNT(phone_number) < 10')
->having('phone_number', '!=', $device->phone_number)
->groupBy('phone_number')->get();
I am trying to select the records where records the same phone_number must be less than 10.
When I run the code, I am getting the following error.
[previous exception] [object] (PDOException(code: 42000): SQLSTATE[42000]: Syntax error or access violation: 1055 'fork.receiver_devices.id' isn't in GROUP BY at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:331)
[stacktrace]
#0 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(331): PDO->prepare('select * from `...')
#1 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(662): Illuminate\\Database\\Connection->Illuminate\\Database\\{closure}('select * from `...', Array)
#2 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(629): Illuminate\\Database\\Connection->runQueryCallback('select * from `...', Array, Object(Closure))
#3 /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php(338): Illuminate\\Database\\Connection->run('select * from `...', Array, Object(Closure))
#4 /var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2149): Illuminate\\Database\\Connection->select('select * from `...', Array, true)
#5 /var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2137): Illuminate\\Database\\Query\\Builder->runSelect()
#6 /var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2609): Illuminate\\Database\\Query\\Builder->Illuminate\\Database\\Query\\{closure}()
#7 /var/www/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2138): Illuminate\\Database\\Query\\Builder->onceWithColumns(Array, Object(Closure))
#8 /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(545): Illuminate\\Database\\Query\\Builder->get(Array)
#9 /var/www/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(529): Illuminate\\Database\\Eloquent\\Builder->getModels(Array)
#10 /var/www/app/Http/Requests/RegisterDeviceRequest.php(72): Illuminate\\Database\\Eloquent\\Builder->get()
#11 /var/www/app/Http/Requests/RegisterDeviceRequest.php(60): App\\Http\\Requests\\RegisterDeviceRequest->registerReceiversFor(Object(App\\Models\\ClientDevice))
#12 /var/www/app/Http/Controllers/Auth/RegisterDeviceController.php(14): App\\Http\\Requests\\RegisterDeviceRequest->persist()
#13 [internal function]: App\\Http\\Controllers\\Auth\\RegisterDeviceController->store(Object(App\\Http\\Requests\\RegisterDeviceRequest))
#14 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#15 /var/www/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\\Routing\\Controller->callAction('store', Array)
#16 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(219): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(App\\Http\\Controllers\\Auth\\RegisterDeviceController), 'store')
#17 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Route.php(176): Illuminate\\Routing\\Route->runController()
#18 /var/www/vendor/laravel/framework/src/Illuminate/Routing/Router.php(681): Illuminate\\Routing\\Route->run()
What is wrong with my code and how can I fix it?
try to do this :-
In config\database.php in mysql array
Set 'strict' => false // to disable all.

running php artisan : Class 'Route' not found

I just took new project, and I'm running into a blocking issue.
When running php artisan without any argument it throws the following error :
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'Route' not found
When running the website homepage, I have an exception and the stack trace found in the logs is the following :
[2017-07-17 13:07:07] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Route' not found in C:\wamp64\www\myproject\routes\api.php:16
Stack trace:
#0 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Routing\Router.php(329): require()
#1 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Routing\Router.php(285): Illuminate\Routing\Router->loadRoutes('C:\\wamp64\\www\\S...')
#2 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Routing\RouteRegistrar.php(104): Illuminate\Routing\Router->group(Array, 'C:\\wamp64\\www\\S...')
#3 C:\wamp64\www\myproject\app\Providers\RouteServiceProvider.php(71): Illuminate\Routing\RouteRegistrar->group('C:\\wamp64\\www\\S...')
#4 C:\wamp64\www\myproject\app\Providers\RouteServiceProvider.php(38): App\Providers\RouteServiceProvider->mapApiRoutes()
#5 [internal function]: App\Providers\RouteServiceProvider->map()
#6 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#7 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#8 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#9 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Container\Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#10 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Support\Providers\RouteServiceProvider.php(71): Illuminate\Container\Container->call(Array)
#11 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Support\Providers\RouteServiceProvider.php(30): Illuminate\Foundation\Support\Providers\RouteServiceProvider->loadRoutes()
#12 C:\wamp64\www\myproject\app\Providers\RouteServiceProvider.php(28): Illuminate\Foundation\Support\Providers\RouteServiceProvider->boot()
#13 [internal function]: App\Providers\RouteServiceProvider->boot()
#14 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#15 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#16 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#17 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Container\Container.php(539): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#18 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(788): Illuminate\Container\Container->call(Array)
#19 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(771): Illuminate\Foundation\Application->bootProvider(Object(App\Providers\RouteServiceProvider))
#20 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(App\Providers\RouteServiceProvider), 17)
#21 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(772): array_walk(Array, Object(Closure))
#22 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\BootProviders.php(17): Illuminate\Foundation\Application->boot()
#23 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(208): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#24 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(162): Illuminate\Foundation\Application->bootstrapWith(Array)
#25 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(146): Illuminate\Foundation\Http\Kernel->bootstrap()
#26 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#27 C:\wamp64\www\myproject\public\index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#28 {main}
I'm very new to laravel, so that might be a newbie mistake, but I didn't manage to find a solution on my own. Can someone help me ?
Thank you for your time.
EDIT:
The culprit was a colleague who wanted to add a "features" array at the end of the config/app.php, and misnamed it "aliases". So everything previously defined was lost.
As I see this question has not been answered for over a month now,
Go to the file where you've used Route::method_name() and import Route class there by->
use Route;
This is common in App\Providers\AppServiceProvider#boot() that implements
Route::resourceVerbs([...]);
Let me know if this helps
In my case I've typed Routes instead of Route.
So pay attention to similar errors like this. Write well the sentences.
Thanks to Thomas Moors, the problem was found.
In the app.php, what was expected :
'aliases' => [
[...]
],
'features' => [
[...]
],
Except instead of 'features' a mistake was made :
'aliases' => [
[...]
],
'aliases' => [
[...]
],
So yeah, nothing worked as expected. Thanks everyone.

Laravel VerifyCsrfToken.php line 53 random on posts

I'm getting an 500 error from server randomly with some (not all!) post requests. After that error, I have to login.
I implemented PDF2HtmlEX that create html pages made with elements and resources like web fonts.
To change page I make a post and get the data but after some page (not always the same) the ajax post return 500 and inside the data (and the log) I see the error:
[2015-12-21 22:17:48] local.ERROR: exception 'Illuminate\Session\TokenMismatchException' in /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:53
Stack trace:
#0 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#1 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#2 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#3 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#4 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#5 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#6 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#7 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#8 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#9 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#10 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#11 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#12 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#13 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#14 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#15 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#16 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#17 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#18 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#19 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#20 /path/to/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#21 /path/to/laravel-project/public/index.php(54): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#22 {main}
Like explaned in the documentation, I add...
<meta name="csrf-token" content="{{ csrf_token() }}">
in the app.blade.php master view templates.
And at the start of js script I add:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
I googled a lot and searched inside stackoverflow but I can't figure it out!
The problem is that the error is occurring somethimes, not always: seems like there is a limit of checks that the token is considered valid.
I use ajax, so the meta tag with token never change across posts.
I'm using laravel 5.1 (5.0 upgraded).
EDIT 1:
I tried to increase 'lifetime' => 120, value inside project/config/session.php: if the value is low (tried 10) I can get this error on 2nd or 3rd post (after 10-20 secs), if the value is hight (tried 9999) I get this error on 30th+ post requests (after 4-5 minutes).
EDIT 2:
I add some log inside the controller and middleware.
I can see all the get requests return correct values, the post error, the other get files started after the post that have the same token inside the ajax header of the post.
I can't see the log of the method of controller that serve post request:
routes.php:
Route::post('/page', "RController#rPageData");
RController.php:
public function rPageData(){
Log::info("I am there!"); # always showed except when error occurred.
# ... other code ...
}
EDIT 3:
More infos: I dumped out $request from a correct post in RController::rPageData(), and a error post request from the Exception handler.
I see that the first 2 lines, userResolver and routeResolver, are null in error post, and well done in correct post. Seems like user is not authenticated, but the nexts GET request, like reported in my EDIT 2, are made correctly.
Error post:
Request {#40 ▼
#json: null
#userResolver: null
#routeResolver: null
...
Good post:
Request {#40 ▼
#json: null
#userResolver: Closure {#144 ▶}
#routeResolver: Closure {#154 ▶}
...
Inside the Request > cookies > headers > parameters > XSRF-TOKEN I have the same token in the 2 posts.
Inside the Request > session > attributes > _token, I have 2 different token in the 2 posts.
EDIT 4:
Well, if you put session_start(); at the top of your routes.php, after <?php tag, it will work.
NOTE: this is not the solution. GrahamCampbell (the second biggest Laravel contributor) said:
NEVER do that! Because that's totally incorrect.
Attach reference
Have you any suggestions?
Thank you in advance!
By default, sessions last 2 hours in Laravel. When they begin to fail have you refreshed the page within 2 hours?
You can increase the length of time sessions will be valid for in config/session.php:
'lifetime' => 120 //120 minutes is 2 hours

Magento front end only printing "local.xml"

I went to do a test customer registration and right after I submitted form, the page only loads what you see below. I deleted cookies and loaded the main page, and it has what you see below as well. My coworker was messing with permissions as well, but we think we have all the permissions correct now. There are no errors in magento logs. The only error on server that may be applicable "client denied by server configuration: /var/www/Staging/public_html/app/etc/local.xml" but I know this is a common error and it's been there. Any ideas about what the issue is?
Update: We added developer mode and now we get the following stack trace:
Warning: simplexml_load_string(): Entity: line 29: parser error : Premature end of data in tag layout line 29 in /var/www/Staging/public_html/app/code/core/Mage/Core/Model/Layout/Update.php on line 444
#0 [internal function]: mageCoreErrorHandler(2, 'simplexml_load_...', '/var/www/Stagin...', 444, Array)
#1 /var/www/Staging/public_html/app/code/core/Mage/Core/Model/Layout/Update.php(444): simplexml_load_string('getFileLayoutUpdatesXml('frontend', 'default', 'f001', '1')
#3 /var/www/Staging/public_html/app/code/core/Mage/Core/Model/Layout/Update.php(347): Mage_Core_Model_Layout_Update->fetchFileLayoutUpdates()
#4 /var/www/Staging/public_html/app/code/core/Mage/Core/Model/Layout/Update.php(246): Mage_Core_Model_Layout_Update->fetchPackageLayoutUpdates('default')
#5 /var/www/Staging/public_html/app/code/core/Mage/Core/Model/Layout/Update.php(224): Mage_Core_Model_Layout_Update->merge('default')
#6 /var/www/Staging/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(306): Mage_Core_Model_Layout_Update->load()
#7 /var/www/Staging/public_html/app/code/core/Mage/Cms/Helper/Page.php(109): Mage_Core_Controller_Varien_Action->loadLayoutUpdates()
#8 /var/www/Staging/public_html/app/code/core/Mage/Cms/Helper/Page.php(52): Mage_Cms_Helper_Page->_renderPage(Object(Mage_Cms_IndexController), 'home')
#9 /var/www/Staging/public_html/app/code/core/Mage/Cms/controllers/IndexController.php(45): Mage_Cms_Helper_Page->renderPage(Object(Mage_Cms_IndexController), 'home')
#10 /var/www/Staging/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Cms_IndexController->indexAction()
#11 /var/www/Staging/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#12 /var/www/Staging/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#13 /var/www/Staging/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#14 /var/www/Staging/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#15 /var/www/Staging/public_html/index.php(87): Mage::run('', 'store')
#16 {main}
1)simplexml_load_string(): Entity is an common error if some xml section is not properly written
2)client denied by server : this error may come because of several reasons
i).htaccess missing
ii)File: /app/code/core/Mage/Adminhtml/Block/Notification/Security.php cooment
private function _isFileAccessible()
//$http->write(Zend_Http_Client::POST, $defaultUnsecureBaseURL . $this->_filePath);
iii)chmod 600 app/etc/local.xml
iv)http://www.yireo.com/tutorials/magento/magento-administration/1322-client-denied-by-server-configuration-appetclocalxml

Resources