Code php test user agent

Résolu/Fermé
olivier - Modifié par BmV le 16/02/2016 à 11:50
 olivier - 16 févr. 2016 à 11:50
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;
}

?>
A voir également:

2 réponses

Chris 94 Messages postés 50978 Date d'inscription mardi 8 janvier 2008 Statut Modérateur Dernière intervention 17 février 2023 7 325
16 févr. 2016 à 11:23
Bonjour,

Pour rappel :
Les réponses sont données par des bénévoles, pas par des machines. Merci d'user des formes simples de politesse.

Et, de plus, l'urgence ne concerne que toi. Les bénévoles qui consacrent leurs temps libres et leurs compétences pour répondre n'ont aucune urgence à le faire. En cas de réelle urgence, il faut consulter un pro.
0
jordane45 Messages postés 38144 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 21 avril 2024 4 650
16 févr. 2016 à 11:27
Bonjour,

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


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