Created
January 15, 2017 04:18
-
-
Save BARNZ/70cb3d4458cf1f9dd4ba4343eee4d2a1 to your computer and use it in GitHub Desktop.
Laravel 5.x middleware to handle hotlinking from MS Apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
/** | |
* This middleware allows us to correctly hotlink to pages from within MS apps. | |
* | |
* It fixes the issue where clicking a link to a page from within MS app (excel/word etc) fails due to the MS app | |
* not sending the correct cookies (resulting in a http 3xx) when it checks if the link is valid. | |
* | |
* @see http://stackoverflow.com/q/2653626 | |
* @see https://support.microsoft.com/en-gb/kb/899927 | |
* | |
*/ | |
class FixMicrosoftLinks | |
{ | |
public function handle($request, Closure $next) | |
{ | |
// Only for requests that come from an MS office product. | |
if (!preg_match('/Word|Excel|PowerPoint|ms-office/i', $request->header('User-Agent'))) { | |
return $next($request); | |
} | |
return response("<html><head><meta http-equiv='refresh' content='0'/></head><body></body></html>", 200); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment