在会话中保存URL参数以便选择退出响应式设计

时间:2013-07-19 11:44:01

标签: php session parameters

我有一个响应迅速的Wordpress网站:www.2eenheid.de。我的客户希望移动设备上的选项以全尺寸方式查看网站,这是一个选择退出的响应选项。现在在一位程序员的帮助下,我得到了这个:

<?php ini_set('display_errors', true);

session_start(); 
if(isset($_REQUEST['resp'])) {
     $_SESSION['resp'] = (bool)($_REQUEST['resp']);
}

// Check if enabled
$enabled = isset($_SESSION['resp']) && $_SESSION['resp'];


?><!DOCTYPE html>

<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />

<?php if($enabled): ?>
    <meta name="viewport" content="width=device-width">
<?php endif; ?>

<title>LALALA</title>

</head>

<body <?php body_class(); ?> id="<?php if(isset($_SESSION['resp']) && $_SESSION['resp']) { echo "resp"; } ?>">

有点有效。每当我调用链接www.2eenheid.de/?resp=1我的网站转向在移动设备上响应时,但当我点击其他页面并且我需要它时它不会保存此设置。还有一些页面是响应性的,有些则不是。我觉得我在$_SESSION['resp'] = (bool)($_REQUEST['resp']);做错了。有人有任何想法吗?

1 个答案:

答案 0 :(得分:0)

试试这个

if(isset($_SESSION['resp'])){
 $enabled = true;
}else{
 $enabled = false;
}

使用此代替

$enabled = isset($_SESSION['resp']) && $_SESSION['resp'];