Laravel redirect::route is showing a message between page loads(Laravel redirect::route 在页面加载之间显示一条消息)
问题描述
我目前正在使用 Laravel 开发一个网络应用程序,直到最近该应用程序运行良好.我不知道是什么触发了它,但这里是我遇到的问题的摘要:
I'm currently developing a web app using Laravel, and the app was working perfectly fine until recently. I had no idea what triggered it but here's a summary of the issue I'm having:
登录过去可以正常工作,因为我有一个 AccountController 可以执行此操作:
Logging in used to work as I have an AccountController that does this:
$auth = Auth::attempt(array(
'username' => Input::get('username'),
'password' => Input::get('password'),
'active'=>1);
if ($auth) {
return Redirect::route('home');
}
return Redirect::route('account-sign-in');
回家路线是这样的:
Route::get('/', array('as'=>'home', 'use'=>'HomeController@show'));
应用程序通常会在成功登录后立即返回主页.在我的 home.blade.php 中,我将有一个 @if(Auth::check())
以确保一旦用户登录,主页将提供不同的服务一组文本.
The app would usually return to home page immediately upon successful login. And in my home.blade.php, I would have an @if(Auth::check())
in place to make sure that once a user is logged in, the home page would serve a different set of texts.
然而,最近,我注意到在提交登录请求后,有一个中间页面显示一条消息重定向到 http://localhost.com/
".在此之前该消息不存在,并且错误开始与此消息一起显示.
Recently however, I noticed that after submitting a request to log in, there's an intermediate page showing a message "Redirecting to http://localhost.com/
". The message was not there prior to this, and the errors started showing up along with this message.
我在网上查找了所有我能找到的信息,有人建议源代码存在换行/空格问题.我查看了我拥有的所有源代码,没有任何迹象表明有什么问题.
I looked up all the information I can online, and someone suggested that there were line break/space issues with the source code. I looked at all the source code I had and nothing would've suggested there's something wrong.
当时很绝望,我删除了 Redirect::route('home') 并用 View::make('home') 代替了它.这阻止了消息显示,我可以像往常一样再次登录.
Desperate at the time, I removed Redirect::route('home') and replaced that with View::make('home') instead. That stopped the message from showing up, and I'm able to login as usual again.
所以我有两个问题:1)是什么导致了这个奇怪的问题?2) 在这种情况下使用 View::make() 与 Redirect::route() 有什么问题吗?
So I have two questions: 1) what is causing this odd issue? 2) is there anything wrong with using View::make() in this case vs Redirect::route()?
谢谢!
推荐答案
我遇到了同样的问题,在花了整个周末寻找真正的原因并解决这个问题之后.我遇到了这个 stackoverflow 问题,感觉和我的问题一样.
I faced same issue and after spending my whole weekend to find actual cause and fix this issue. I landed on this stackoverflow question and felt its same issue as that of mine.
我使用以下核心 php 函数进行重定向,而不是从控制器返回视图文件.
I used following core php function to redirect instead of returning a view file from controller.
header('Location: /');
它打印了有空行的实际文件.删除此行解决了我的问题.
It printed actual file which had blank line. Removing this line fixed my problem.
我的代码库中有数千个文件.我的假设是我尝试了不同的脚本来在任何文件的开头找到这样的空行,并且根据这些脚本结果没有这样的文件.我假设我的任何文件中都没有空行.但是 header('Location:/') 证明我的假设是不正确的,我在错误的行上工作.
There were thousands of files in my code base. My assumption was that I have tried different scripts to find such blank lines at start of any file and there was no such file as per those scripts results. I assumed there is is no blank line in any of my files. But header('Location: /') proved that my assumption was not correct and I was working on wrong lines.
这篇关于Laravel redirect::route 在页面加载之间显示一条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel redirect::route 在页面加载之间显示一条消息
基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01