Daellus
Daellus

Reputation: 37

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. It's working great adding ?det=0 for not mobile or ?det=1 if it is a mobile browser. However, in my header file, my IF statement is always returning the not-mobile html regardless of the value of det in the url. 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

Excerpted from the < head > section of 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" />

Upvotes: 1

Views: 155

Answers (1)

Will
Will

Reputation: 301

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!

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

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

$mob = $_GET['det'];

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

Upvotes: 1

Related Questions