Getting the screen resolution using PHP

前端 未结 21 1854
你的背包
你的背包 2020-11-22 06:50

I need to find the screen resolution of a users screen who visits my website?

相关标签:
21条回答
  • 2020-11-22 07:26

    I found using CSS inside my html inside my php did the trick for me.

    <?php             
        echo '<h2 media="screen and (max-width: 480px)">'; 
        echo 'My headline';
        echo '</h2>'; 
    
        echo '<h1 media="screen and (min-width: 481px)">'; 
        echo 'My headline';
        echo '</h1>'; 
    
        ?>
    

    This will output a smaller sized headline if the screen is 480px or less. So no need to pass any vars using JS or similar.

    0 讨论(0)
  • 2020-11-22 07:26

    You can check it like below:

    if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile') || strstr(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
       echo "mobile web browser!";
    } else {
    echo "web browser!";
    }
    
    0 讨论(0)
  • 2020-11-22 07:27
    <script type="text/javascript">
    
    if(screen.width <= 699){
        <?php $screen = 'mobile';?>
    }else{
        <?php $screen = 'default';?>
    }
    
    </script>
    
    <?php echo $screen; ?> 
    
    0 讨论(0)
提交回复
热议问题