Classe mobile provenance PHP
Exemple code
<!DOCTYPE html>
<html lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Tuto Detecte mobile</title>
<link rel="stylesheet" type="text/css" href="...Mon-css.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- L'appel de la classe mobile est à placer idéalement juste après la balise </head> -->
</head>
<?php
include('Classe_Mobile_Detect.php');
$detect = new Mobile_Detect();
?>
<body>
<header>
<!-- ////// -->
</header>
<section>
<div class="">
<h1>Test en Direct :</h1>
<div style="width:50%;">
<img src="/img_demo/19.webp" class="" alt="Affichage Mobile" style="height:117px;">
</div>
Le piaf
<div style="width:50%;">
<img src="/img_demo/15.webp" class="" alt="Affichage Bureau" style="height:117px;">
</div>
Jaquot
<br /> <br />
<span class="">L'une des images, Le piaf ou Jaquot, sera affichée si-dessous:
<br />
Selon que vous êtes connecté depuis un ordi ou un mobile.
<br />
Vous pouvez simuler une connection mobile, depuis un ordi, par exemple:
<br />
Sous Firefox >> Menu >> Développement Web >> Vue adaptative >> puis <span style="color:#FF0000;">actualisez</span> la page.
</span>
<br /> <br />
<?php
if ($detect->isMobile()) {
$img_affich ='<img src="/img_demo/19.webp" class="" alt="Affichage Mobile">';
$provenance = "Mobile";
$nom_img = "Le piaf";
}
?>
<?php
if (!$detect->isMobile()) {
$img_affich ='<img src="/img_demo/15.webp" class="" alt="Affichage Bureau">';
$provenance = "Bureau";
$nom_img = "Jaquot";
}
?>
Actuellement vous êtes sur <span class=""><?php echo $provenance ?></span>
<div class="image">
<?php echo $img_affich ?>
</div>
<?php echo $nom_img ?>
<br /> <br />
<br />
<br />
</div>
</section>
<footer>
<!-- ////// -->
</footer>
</body>
</html>