Code php test user agent

Résolu
olivier - 16 févr. 2016 à 11:14
 olivier -
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 58330 Statut Modérateur 7 346
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 40050 Statut Modérateur 4 753
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