【问题标题】:php URL variable doesn't seem to be workingphp URL 变量似乎不起作用
【发布时间】:2019-02-11 18:13:36
【问题描述】:

我修改了 detectmobilebrowsers.com php 脚本,在重定向中传递的 url 中写入 1 或 0,这样我就可以根据查看浏览器是否为移动设备编写我需要的样式表。如果是移动浏览器,添加?det=0?det=1 非常有用。但是,在我的头文件中,无论 url 中 det 的值如何,我的 IF 语句总是返回非移动 html。我确定这是初级的,但我无法理解!

我使用的网址格式是 www.cypressbotanicals.com/main.php?det=1

摘自header.php的

部分:
<?php
$mob = $_GET['$det'];
if($mob==1): ?>
<link rel="stylesheet" href="css/mobile.css" type="text/css" media="screen" /><!--is mobile-->
<?php else: ?>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<?php endif ?>
<link rel="stylesheet" href="css/scheck.css" type="text/css" media="screen" />

【问题讨论】:

  • 试试$_GET['det'];(从数组键名中去掉$
  • 当然,就是这样!谢谢!

标签: php html variables url get


【解决方案1】:

问题是,当您运行 $_GET 时,您正在寻找以 $ 为前缀的东西,它用于 PHP 变量,但不是这个!

$mob = $_GET['$det'];

将寻找https://example.com/index.php?$det=foo

$mob = $_GET['det'];

将寻找https://example.com/index.php?det=foo

【讨论】:

  • 谢谢!我知道这一定是因为 if 语句的后半部分正在执行。
猜你喜欢
  • 1970-01-01
  • 2015-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多