Skip to content

Instantly share code, notes, and snippets.

@adeekshith
Created December 4, 2014 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adeekshith/c06c752fec77e644fcad to your computer and use it in GitHub Desktop.
Save adeekshith/c06c752fec77e644fcad to your computer and use it in GitHub Desktop.
This PHP script detects browser and redirects to a different link for each browser. I made this for my Docs Online Viewer banner.
<?php
/*
Detects browser and redirects to a different link for each browser.
*/
$browser = $_SERVER['HTTP_USER_AGENT'];
$chrome = '/Chrome/';
$firefox = '/Firefox/';
$ie = '/MSIE/';
if (preg_match($chrome, $browser)){
//echo "chrome/opera";
header( 'Location: https://chrome.google.com/webstore/detail/docs-online-viewer/gmpljdlgcdkljlppaekciacdmdlhfeon?hl=en' ) ;
}
elseif (preg_match($firefox, $browser)){
//echo "firefox";
header( 'Location: https://addons.mozilla.org/en-us/firefox/addon/docs-online-viewer/' ) ;
}
elseif (preg_match($ie, $browser)){
//echo "internet_explorer";
header( 'Location: http://www.deekshith.in/p/docs-online-viewer.html' ) ;
}
else{
header( 'Location: http://www.deekshith.in/p/docs-online-viewer.html' ) ;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment