Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location headers in Laravel

I'm working with a Library for my university's authentication system (Ucam_Webauth) which means I have to redirect to the authentication server in one of the methods. Unfortunately, I cannot return a Redirect:to() because of the architecture of this library. The library itself uses header('Location: ...'); but this isn't working for some reason.

If I make the programme die(); after sending the header it works, but otherwise it doesn't.

Any idea how I can fix this?

like image 260
GTF Avatar asked Mar 26 '13 17:03

GTF


People also ask

How do I get headers in laravel?

Laravel provides many details in Illuminate\Http\Request class object. You can simply get headers details using headers() method. This will return all headers in array.

What is header location?

The Location response header indicates the URL to redirect a page to. It only provides a meaning when served with a 3xx (redirection) or 201 (created) status response.

Where is header located in PHP?

PHP Header Location In order for your PHP redirect to be successful, the header() function must execute — and before any output is sent. This is why your code must appear above the <! DOCTYPE html> or <html> tags in your index. php file.


2 Answers

return redirect()->to('url')->send();

Sends HTTP headers and content. In my application, send() method acts like 'exit()' and is testable

like image 188
Alex Avatar answered Oct 07 '22 23:10

Alex


I'm not sure I follow. Laravel sets the Location header as part of the Redirect::to() method. If you want to more explicitly define the response you could do it like this.

return Response::make( '', 302 )->header( 'Location', $url );

If that doesn't work I'd probably just fall back on the php stdlib header() and return null.

If all of this still doesn't do any good, maybe the profiler is messing things up. If it is turned on, try disabling it in the config.

like image 23
Collin James Avatar answered Oct 08 '22 01:10

Collin James