Anybody?
Laravel suddenly displays redirecting page?
Hi!
This must be a new thing. I have noticed lately that laravel displays "redirecting to" page (blank page with redirect link).
How can i turn it off??
Seems like this is causing it.
https://github.com/symfony/http-foundation/blob/master/RedirectResponse.php
Line 81+
The file there havent been updated for 3 months... but something is causing it.
The redirect page appears when request validation fails or you do redirect()->something.
@Dreamer that can be caused by different things, most have ran into that problem because they had some characters (or empty space) before the <?php on top of one of their PHP files which would prevent the headers from being properly sent, some have had the wrong server configuration..
I would suggest you start checking the PHP files you've worked on since this problem occurred to make sure all start with <?php and nothing else.
@Prez Thanks, ill try!
@Prez Cant seem to find the file. I checked all files that i have added/changed but every one of them had php tag at the very beginning of the file. It must be something global too because it happens everywhere - failed login, failed request validation, using redirect() anywhere.
Something i just found out. If i do php artisan optimize i get this...
$ php artisan optimize
[32mGenerating optimized class loader[39m
$ php artisan migrate
[32mNothing to migrate.[39m
I am not sure if these problems are related cause i cant remember if i have used any commands after the redirect problem started.
Check your logs file and see if you can find something there.
No errors in log when doing redirect or console commands.
@Dreamer do you use git? If so can you go back to a version that worked or see the changes you've made since then..
Alternatively, if you haven't come very far you could create a new project and first see if the redirect works there and then start to move your code there and see if that solved the problem.
check utf8 boom in the files
I do use git but, i have made A LOT of commits before i was even touching anything above routes. It would be very hard to test as i would have to make a view and routes for every state i would test.
What are the other reasons this problem would appear? Besides invalid file beginning? Ill take a new look at file beginnings...
I think you missed my comment as a lot of times is just the utf8 boom
@Dreamer like @boynet has mentioned, make sure your files are saved as utf8 without boom.
When you create a redirect, Laravel sets a location header and also HTML meta refresh (the redirect page you see) as a fall-back. This means something in your app/server is preventing Laravel from setting the location header, hence why you see the redirect page.
What happens if you create a simple redirect route, does it still show the redirect page?
// If you visit YourApp.com/test this should redirect you to YourApp.com/
// Does this show redirect page?
Route::get('/test', function() {
return redirect()->to('/');
});
Thanks, yeah, i missed it. But i tried running
grep -rl $'\xEF\xBB\xBF' .
on my project using Git Bash on Windows. All files it found were on public folder and not anything that is included into php (js, xml).
Source: http://stackoverflow.com/questions/204765/elegant-way-to-search-for-utf-8-files-with-bom
Is there a way to find a file that has not php tag at the very beginning?
EDIT: @Prez I tried it and it did not produce fall-back redirect page. It redirected properly. Hmm..
@Dreamer try this in your project root
find . -type f -name "*.php" -print0 | xargs -0 -I{} awk 'NR==1&&!/^<\?php/{print FILENAME}' {}
It should print out the file name of every .php file that does not start with <?php
You can obviously ignore files it shows in the /resources, /storage and probably /vendor as well
I have similar issue when I attempt to login, using the command you gave here, there's no file shown not syntaxed properly.
My issue is:
_token=QCEwN6Og4SvaTkUvVXcmlaofLawckSGX1R9nFVZN&email=emails%40email.com&password=mypassword Redirecting to https:/my-app.com/dashboard
Something like that would be shown briefly then goes back to the login page.
Sometimes, maybe like 2 times a week, when I use a private mode, it works, like, I am able to login.
@SaeedPrez Wow, 8 years ago... this fixed it for me, I already looked for unnecessary characters but not white spaces, plus the command-line code was just awesome.. thanks a lot
Thanks for trying to help me. I tried it and this was the result:
$ find . -type f -name "*.php" -print0 | xargs -0 -I{} awk 'NR==1&&!/^<\?php/{print FILENAME}' {}
./public/js/plugins/ckeditor/samples/old/assets/posteddata.php
./resources/views/app.blade.php
./resources/views/auth/emails/password.blade.php
./resources/views/auth/login.blade.php
./resources/views/auth/passwords/email.blade.php
./resources/views/auth/passwords/reset.blade.php
./resources/views/auth/register.blade.php
./resources/views/errors/503.blade.php
./resources/views/front.blade.php
./resources/views/layouts/app.blade.php
./resources/views/pages/blank.blade.php
./resources/views/pages/blank_app.blade.php
./resources/views/pages/clients/create.blade.php
./resources/views/pages/clients/list.blade.php
./resources/views/pages/clients/profile.blade.php
./resources/views/pages/notices.blade.php
./resources/views/pages/offers/create.blade.php
./resources/views/pages/offers/list.blade.php
./resources/views/pages/test.blade.php
./resources/views/partials/clients/main_info.blade.php
./resources/views/partials/clients/select_form.blade.php
./resources/views/partials/clients/select_options.blade.php
./resources/views/partials/menus/app_main.blade.php
./storage/framework/views/119694f73aad6bd793ca1f2c0223876a747d120a.php
./storage/framework/views/2f248e3490fc9bef19dd385f39f17985daf3d4cd.php
./storage/framework/views/35ebfe9115200249ed8734a10b9932367288f36d.php
./storage/framework/views/5f4a817cefc4bbeca4f6c6795c4bd48761d18155.php
./storage/framework/views/98592eece7da4b280497a9e41bf6d6ae7fe11a2b.php
./vendor/phpunit/phpunit/build/phar-manifest.php
./vendor/phpunit/phpunit/build/phar-version.php
./vendor/swiftmailer/swiftmailer/lib/swiftmailer_generate_mimes_config.php
Hm, other things I can think of that would cause this are...
- If you use closing PHP tags
?>, you shouldn't really use them unless there is a specific need, like mix of PHP and HTML in same file. - If you use cookies in your app, try disabling that and test if that helps
- If you have
echo,print,var_dump, etc somewhere
Thanks. I have never closed php tag in Laravel. I tried to find "dump(" command from app folder but there was not any and im sure i never used echo or anything like that, i always use dd or dump.
Ill check about the cookies... How do i disable them anyway?
But if that fails... im not sure what to do :) I guess ill try to move the whole project into new laravel install and see if that works.
BTW, i a using PHP 7 if that makes any difference...
@Dreamer I'm using PHP 7 as well with XAMPP on Windows 10 for my development environment and it's working well.
I'm out of ideas what it can be, especially since the redirect works when done in the route. If you're using cookies, just comment it out I guess, but hopefully you'll find what's causing it soon.
If you decide to move to a new project, make sure you only copy the code you've added, don't copy/move files or select all content of a file, move bit by bit and keep trying the redirect to see if any addition of code breaks it.
Edit: Try run these commands just for laughs..
composer dump-autoload
php artisan cache:clear
php artisan optimize
Yeah, i have the same environment. Ill guess ill try to fix it by moving it to clean project when i have time to screw around :)
Sorry for revive an old post, but the solution of @SaeedPrez worked to me.
After the execution of the command:
find . -type f -name "*.php" -print0 | xargs -0 -I{} awk 'NR==1&&!/^<\?php/{print FILENAME}' {}
They returned the config/app.php, when I looked at the file, there was a blank space before the <?php
Thank you very much!
I know that this is an old thread, but in case anyone stumbles upon this from Google search as I did: The issue may also be caused by a call to the flush() method.
Simple way to try this out: put this into your routes file:
Route::get('testFlush', function () {
flush();
return redirect("/");
});
In my case the issue occurred because some code that I was using to call console commands was flushing output. So when running those commands in a POST request from the browser, suddenly the "Redirecting to ..." started showing up.
Running PHP 5.6.25 on WAMP on Windows 10 x64 if anyone was concerned.
I am having the same issue with swift display of redirect and auth credentials when I login. It ends up going back to login page. I tried your snippet now and I can see the the swift display of the redirection.
I don't use flush anywhere in my code, below is my super admin login auth handler:
/**
* Login processes login form and authenticates user
* @param Request
*/
public function store(Request $request){
$credentials = $request->validate([
'email' => ['required', 'email'],
'password' => ['required'],
]);
if (Auth::guard("admin")->attempt($credentials)) {
$request->session()->regenerate();
$intendedRoute = $request->session()->get('url.intended');
if ($intendedRoute && Str::startsWith($intendedRoute, 'super.')) {
return redirect()->intended(route('super.dashboard'));
}
return redirect()->route('super.dashboard');
}
return redirect()->route('super.login.show')
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => trans('auth.failed'),
]);
}
@SAEEDPREZ - OK, you just saved me hours! Thank you! It was one errant space.
@saeedprez thanks, 4 real thanks man
@saeedprez Love you Boss..
OMG. I was pulling my hair out for several hours. I was so pissed. LOL. Turned out I had created a new config file and had a carriage return before my opening <?php.
Thanks!
Please or to participate in this conversation.