php - 拉维尔 |错误: Header may not may not contain more than a single header

标签 php laravel http http-headers laravel-5.4

我已经在我的 laravel 5.4 项目中实现了Multi-Auth,但是每当我尝试从其他设备登录时,我都会收到此错误。

ErrorException in Response.php line 386:Header may not contain more than a single header, new line detected

现在我尝试查看该网站中的其他类似问题,但没有一个与我在登录 Controller 中所做的相匹配。

这是我的登录 Controller :

   class LoginController extends Controller
{


    use AuthenticatesUsers;   

    public function __construct()
    {
        $this->middleware('guest', ['except' => 'logout']);
    }

    public function username()
    {
        return 'mobile_no';
    }

    protected function redirectTo( )
    {
        $notification = array(
            'message' => 'Welcome Admin!', 
            'alert_type' => 'info',
            'title' => Auth::user()->name
        );
        return redirect('/home')->with('notification', $notification);
    }
}

我的 redirecTo() 函数出了什么问题?

最佳答案

这个问题已经得到解答here 。 基本上你的方法应该返回一个字符串而不是重定向响应。 这是一个例子:

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
     /*
     |--------------------------------------------------------------------------
     | Login Controller
     |--------------------------------------------------------------------------
     |
     | This controller handles authenticating users for the application and
     | redirecting them to your home screen. The controller uses a trait
     | to conveniently provide its functionality to your applications.
     |
     */

     use AuthenticatesUsers;

     /**
      * Where to redirect users after login.
      *
      * @var string
      */
     //protected $redirectTo = '/';

     /**
      * Create a new controller instance.
      *
      * @return void
      */
     public function __construct()
     {
          $this->middleware('guest')->except('logout');
     }

     public function redirectTo(){
          return '/admin';
     }


}

但是因为您实际上需要重定向到 View 并包含一些对您不起作用的数据。您需要的是完全覆盖重定向功能并创建您自己的 . 这是您需要做的。您可以从这里复制整个类,它应该开箱即用:)。这是代码。干杯。

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;

class LoginController extends Controller
{
     /*
     |--------------------------------------------------------------------------
     | Login Controller
     |--------------------------------------------------------------------------
     |
     | This controller handles authenticating users for the application and
     | redirecting them to your home screen. The controller uses a trait
     | to conveniently provide its functionality to your applications.
     |
     */

     use AuthenticatesUsers;

     /**
      * Where to redirect users after login.
      *
      * @var string
      */
     //protected $redirectTo = '/';

     /**
      * Create a new controller instance.
      *
      * @return void
      */
     public function __construct()
     {
          //this should not be included
          //$this->middleware('guest')->except('logout');
     }

     //public function redirectTo(){
     //     return '/admin';
     //}
     protected function authenticated()
 {
      $notification = array(
          'message' => 'Welcome Admin!',
          'alert_type' => 'info',
          'title' => Auth::user()->name
      );
      return redirect('/home')->with('notification', $notification);
 }

}

关于php - 拉维尔 |错误: Header may not may not contain more than a single header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022656/

相关文章:

php - 更改模型名称 Laravel

java - 转义 HTTP 请求中的斜杠

php - 处理空值和 JSON

php - 如何在 PHP 的 Ubuntu 13.10 上通过 GSM 使用 gsmsendsms 发送中文短信?

php - 如果期望值从 Laravel 的下拉列表中选择,如何获取另一个字段?

http - HA 代理使用 tcp-check 进行 HTTP 连接

python - 我应该使用哪种协议(protocol)来传输音频(非直播)?

php - 选择周围的行 php/mysql

php - 如何使用文本框异步编辑/更新静态 mysql 结果?

php - Laravel 查询不返回任何数据