Skip to content

Instantly share code, notes, and snippets.

@pascalchevrel
Last active December 19, 2015 05:48
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 pascalchevrel/5906395 to your computer and use it in GitHub Desktop.
Save pascalchevrel/5906395 to your computer and use it in GitHub Desktop.
check fx version is valid
<?php
function isValidFirefoxDownload() {
if (!isset($_GET['product'])) {
return false;
}
global $config;
$versionDetails = (int) str_replace('firefox-', '', $_GET['product']);
// If $versionDetails == 0 it means that the version number is a
// potentially valid keyword such as latest, stub, beta...
$majorVersion = ($versionDetails == 0) ? LATEST_FIREFOX_VERSION : $versionDetails;
// List of validity checks. Can be extended. Boolean values.
$valid = array(
isset($_SERVER['HTTP_REFERER']),
(bool) strstr($_SERVER['HTTP_REFERER'], $config['server_name']),
($majorVersion < (int) LATEST_FIREFOX_VERSION) ? false : true,
);
// We don't want to redirect requests for ESR or Thunderbird
if ((bool) strstr($_GET['product'], 'esr')
|| (bool) strstr($_GET['product'], 'thunderbird')) {
return true;
}
// If we have failed constraints, a filtered array will be smaller
if (count($valid) > count(array_filter($valid))) {
return false;
}
return true;
}
// Redirect non-latest versions of Firefox download requests (Bug 887940)
if (!isValidFirefoxDownload()) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: /firefox/new/');
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment