使用以下 PHP 代码可以检测用户的 UA,并在手机 UA 访问时显示按钮,电脑 UA 访问时不显示按钮:

<?php
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $is_mobile = preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $user_agent);
    
    if ($is_mobile) {
        echo '<button>Button</button>';
    }
?>

在电脑 UA 访问时,将不会显示该按钮。

PHP 手机 UA 访问显示按钮,电脑 UA 访问隐藏 - 代码示例

原文地址: https://www.cveoy.top/t/topic/m1yS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录