Code php test user agent

Résolu
Bonjour Tout le monde !
Je viens Ver vous car j'aurais besoin d'aide et de conseiller, voilà j'ai développé un site web en Php et je voudrais incorporer un module qui permet de tester les navigateurs qui rentrent sur le site et n'autorise à accéder au site que ceux qui sont 1 version en dessous des versions récentes des navigateurs.

en somme interdire l'accès à tous les navigateurs qui ne sont pas à jour en prenant en compte de faire la redirection que s'ils sont sur un navigateur inférieur à 2 versions récentes.

J'espère que vous comprenez là où je veux en venir, voici déjà une portion de code:

<?php

if (ereg("MSIE 6.0", $_SERVER["HTTP_USER_AGENT"])) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
} 


else if (ereg("MSIE 7", $_SERVER["HTTP_USER_AGENT"])) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
} 


else if (ereg("MSIE 8", $_SERVER["HTTP_USER_AGENT"])) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
exit;
} 


else if (ereg("MSIE 10", $_SERVER["HTTP_USER_AGENT"])) {
echo '<link rel="stylesheet" href="css/style.css">';
} 


else if ((ereg("Mozilla/", $_SERVER["HTTP_USER_AGENT"])) && (!ereg("Firefox", $_SERVER["HTTP_USER_AGENT"])) && (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]))) {
echo '<link rel="stylesheet" href="css/style.css">';
} 


else if ((ereg("Mozilla/4", $_SERVER["HTTP_USER_AGENT"])) && (!ereg("Firefox", $_SERVER["HTTP_USER_AGENT"])) && (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]))) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
}


else if ((ereg("Mozilla/5", $_SERVER["HTTP_USER_AGENT"])) && (!ereg("Firefox", $_SERVER["HTTP_USER_AGENT"])) && (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]))) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
} 


else if ((ereg("Mozilla/2", $_SERVER["HTTP_USER_AGENT"])) && (!ereg("Firefox", $_SERVER["HTTP_USER_AGENT"])) && (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]))) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
exit;
}


else if (ereg("Firefox/", $_SERVER["HTTP_USER_AGENT"])) {
echo '<link rel="stylesheet" href="css/style.css">';
}


else if (ereg("Chrome/", $_SERVER["HTTP_USER_AGENT"])) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
exit;
}


else if (ereg("Safari/", $_SERVER["HTTP_USER_AGENT"])) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
exit;
}



else if (ereg("Opera/", $_SERVER["HTTP_USER_AGENT"])) {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
exit;
}



else {
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
exit;
}


if(preg_match('/(CriOS)\//i',$_SERVER['HTTP_USER_AGENT']) && !preg_match('/(Aviator|ChromePlus|coc_|Dragon|Edge|Flock|Iron|Kinza|Maxthon|MxNitro|Nichrome|OPR|Perk|Rockmelt|Seznam|Sleipnir|Spark|UBrowser|Vivaldi|WebExplorer|YaBrowser)/i',$_SERVER['HTTP_USER_AGENT'])){
header('Location: https://www.browser-update.org/fr/update.html');
echo '<META http-equiv="refresh" content="0;URL=https://www.browser-update.org/fr/update.html">';
exit;
}

?>

2 réponses

  1. Modérateur
    Bonjour,

    Déjà .. je t'invite à utiliser la class Browser pour détecter la version du navigateur
    https://github.com/cbschuld/Browser.php

    0
    1. Merci pour cette class je vais débrouillez avec ça
      0