Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP会话仅在GET存在时工作_Php_Variables_Session - Fatal编程技术网

PHP会话仅在GET存在时工作

PHP会话仅在GET存在时工作,php,variables,session,Php,Variables,Session,我已经尝试解决这个问题好几个小时了,在这里我已经阅读了很多文章,但是我仍然找不到一个有效的答案 我希望用户能够设置其默认货币,而不必在每个页面上都设置,因此我在所有页面上都有此会话代码: <?php session_start(); if (isset($_GET['currency'])) { $_SESSION['currency'] = $_GET['currency']; } ?> 我的货币选择器是: <a href="index.php?curre

我已经尝试解决这个问题好几个小时了,在这里我已经阅读了很多文章,但是我仍然找不到一个有效的答案

我希望用户能够设置其默认货币,而不必在每个页面上都设置,因此我在所有页面上都有此会话代码:

<?php
session_start();

if (isset($_GET['currency'])) {
$_SESSION['currency'] = $_GET['currency'];
}

?>

我的货币选择器是:

<a href="index.php?currency=EUR">EUR</a>
<a href="index.php?currency=USD">USD</a>
<a href="index.php?currency=GBP">GBP</a>

当我显示货币时,我使用以下方法:

<?php print isset($_SESSION['currency']) ? "{$_SESSION['currency']}" : 'usd'; ?>

我们的想法是使用美元作为默认货币,但是如果没有?currency=变量,这个设置就无法工作,当我设置变量时,它不会被保存

我错过了什么


谢谢

@FunkFortyNiner谢谢你的关注。不,实际代码中没有空格。我在看到编辑时删除了我的评论。您是否在第二个文件中启动了会话?错误报告显示了什么?@FunkFortyNiner我在所有页面上使用相同的代码,因此我在每个页面上启动会话。没有错误。cookie/浏览器调试在哪里?@FunkFortyNiner修复了它!编码必须是无BOM的UTF-8才能工作@FunkFortyner感谢您的关注。不,实际代码中没有空格。我在看到编辑时删除了我的评论。您是否在第二个文件中启动了会话?错误报告显示了什么?@FunkFortyNiner我在所有页面上使用相同的代码,因此我在每个页面上启动会话。没有错误。cookie/浏览器调试在哪里?@FunkFortyNiner修复了它!编码必须是无BOM的UTF-8才能工作!