Laravel 5.1 gives 'undefined index: http_host ' when run 'php artisan serve'

Viewed 8026

I learned laravel using version 5.4 for 6 months. i installed latest xampp then. But now i got to work on a project built on laravel 5.1. But when i want to run the app, it gives me the error (undefined index: http_host)! How can i find where the error comes from? How can i solve the problem? I searched online but nothing found fruitful. Can you help me, please? Storage/log.php:

[2017-07-18 21:55:50] local.ERROR: ErrorException: Undefined index: HTTP_HOST in H:\Current\school\school\app\Providers\AppServiceProvider.php:40

Stack trace:

#0 H:\Current\school\school\app\Providers\AppServiceProvider.php(40): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', 'H:\\Current\\scho...', 40, Array)
#1 [internal function]: Erp\Providers\AppServiceProvider->boot()
#2 H:\Current\school\school\vendor\laravel\framework\src\Illuminate\Container\Container.php(507): call_user_func_array(Array, Array)
#3 H:\Current\school\school\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(734): Illuminate\Container\Container->call(Array)
#4 H:\Current\school\school\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(717): Illuminate\Foundation\Application->bootProvider(Object(Erp\Providers\AppServiceProvider))
#5 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(Erp\Providers\AppServiceProvider), 18)
#6 H:\Current\school\school\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(718): array_walk(Array, Object(Closure))
#7 H:\Current\school\school\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\BootProviders.php(17): Illuminate\Foundation\Application->boot()
#8 H:\Current\school\school\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(203): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(Illuminate\Foundation\Application))
#9 H:\Current\school\school\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(208): Illuminate\Foundation\Application->bootstrapWith(Array)
#10 H:\Current\school\school\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(105): Illuminate\Foundation\Console\Kernel->bootstrap()
#11 H:\Current\school\school\artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 {main}  

AppServiceProvider:

public function boot()

{

    if(!Session::get(SITE_ID)){
        $subdomain_name = array_shift((explode(".",$_SERVER['HTTP_HOST'])));
        if(isset($subdomain_name) && !empty($subdomain_name)){
            $domain = $subdomain_name;
        }else{
            $domain = "school";
        }
        $siteToRecollect = DB::table('site_infos')->where('site_alias',$domain)->first();

        if(isset($siteToRecollect->id) && !empty($siteToRecollect->id) && $siteToRecollect->id != 0){

            Session::put(SITE_ID,$siteToRecollect->id);

        }else{

            Session::put(SITE_ID,1);

        }

    }

}

40 line:

$subdomain_name = array_shift((explode(".",$_SERVER['HTTP_HOST'])));
1 Answers
Related