I am having trouble understanding this logic:
I am using JavaScript to detect the browser width and passing that value to PHP as a session variable using the following code.
<?php
session_start()
if (empty($_SESSION['layoutType'])) {
echo '<script type="text/javascript"> var session=false; var layoutType;</script>';
} else {
echo '<script type="text/javascript"> var session=true; var layoutType=' . $_SESSION['layoutType'] . ';</script>';
}
if (!empty($_SESSION['layoutType'])) {
$layoutType = $_SESSION['layoutType'];
if ( $layoutType <= 219 ) {
$layout = 'mobile';
} else if ($layoutType >= 220 && $layoutType <= 1024 ) {
$layout = 'tablet';
} else {
$layout = 'desktop';
}
}
echo $layout;
This correctly displays the value as mobile or tablet or desktop depending on the browser width. But when I try to use the same variable and paste the following code below the above code, it changes the value of $layout:
function getFevicons(){
if ( $layout = 'mobile' ); {
echo '
<link rel="apple-touch-icon" href="cdn/images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="cdn/images/apple-touch-icon-72.png">
<link rel="apple-touch-icon" sizes="114x114" href="cdn/images/apple-touch-icon-114.png">
';
}
echo $layout;
}
?>
Even though the layout is for the desktop, it now gives the output as mobile and also it echos the above favicon links. Why?
Am I doing something wrong?
Call your function like so (
getFevicons($layout);):