您可以使用以下代码来检测用户的 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 html按钮 手机ua访问显示按钮 电脑ua访问不显示

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

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