找回密码
 立即注册
搜索
热搜: 生活 中国

全局数组$_REQUEST[]获取屏幕大小尺寸

[复制链接]
admin 发表于 2020-9-26 22:49:01 | 显示全部楼层 |阅读模式
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>全局数组$_REQUEST[]获取屏幕大小</title>
  6. </head>

  7. <body>
  8. <p>$_REQUEST[]全局数组获取GET方法、POST方法和http Cookie传递到脚本的信息。如果在编写程序时,不能确定通过什么方法的数据,那么就可以通过$_REQUEST[]全局数组获取提交到当前页面的数据。</p>
  9. <?php
  10. if(isset($_REQUEST['width']) AND isset($_REQUEST['height'])){
  11.     echo '<p>'.'获取屏幕尺寸: ' . $_REQUEST['width'] . 'x' . $_REQUEST['height'].'</p>';
  12. } else {
  13.     echo '<script type="text/javascript">window.location = "' . $_SERVER['PHP_SELF'] . '?width="+screen.width+"&height="+screen.height;</script>';
  14. }
  15. ?>
  16. </body>
  17. </html>
复制代码


回复

使用道具 举报

 楼主| admin 发表于 2020-11-11 01:23:27 | 显示全部楼层
  1. <?php
  2. if (isset($_GET['width']) AND isset($_GET['height'])) {
  3.     // output the geometry variables
  4.     echo "Screen width is: " . $_GET['width'] . "<br />\n";
  5.     echo "Screen height is: " . $_GET['height'] . "<br />\n";
  6. } else {
  7.     // pass the geometry variables
  8.     // (preserve the original query string
  9.     //   -- post variables will need to handled differently)

  10.     echo "<script language='javascript'>\n";
  11.     echo "  location.href="${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
  12.         . "&width=" + screen.width + "&height=" + screen.height;\n";
  13.     echo "</script>\n";
  14.     exit();
  15. }
  16. ?>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|生活导航|生活导航 ( 新ICP备12003026-1号 )

GMT+8, 2024-4-26 07:13 , Processed in 0.074568 second(s), 14 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表