简体   繁体   English

php URL 变量似乎不起作用

[英]php URL variable doesn't seem to be working

I modified the detectmobilebrowsers.com php script to write 1 or 0 in the url passed in the redirect so I can just script which style sheet I need based on if the viewing browser is mobile or not.我修改了 detectmobilebrowsers.com php 脚本,在重定向中传递的 url 中写入 1 或 0,这样我就可以根据查看浏览器是否移动来编写我需要的样式表的脚本。 It's working great adding ?det=0 for not mobile or ?det=1 if it is a mobile browser.添加?det=0对于非移动设备或?det=1如果它是移动浏览器,效果很好。 However, in my header file, my IF statement is always returning the not-mobile html regardless of the value of det in the url.但是,在我的头文件中,无论 url 中det的值如何,我的 IF 语句始终返回非移动 html。 I'm sure this is elementary, but I can't get it!我确定这是基本的,但我无法理解!

the url format i'm using is www.cypressbotanicals.com/main.php?det=1我使用的 url 格式是 www.cypressbotanicals.com/main.php?det=1

Excerpted from the < head > section of header.php:摘自header.php的<head>部分:

<?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" />

The issue is that when you're running your $_GET , you're looking for something that's prefixed with a $ , which is used for PHP variables, but not this!问题是,当你运行你$_GET ,你要找的东西是有前缀$ ,这是用于PHP变量,但不是这个!

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

Will look for https://example.com/index.php?$det=foo会寻找https://example.com/index.php?$det=foo

$mob = $_GET['det'];

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM