我的文件中有以下代码段: -
session_start();
$_SESSION['fromPanel'] = "abcd";
<form method="post" action="/m/xyz.php">
<div class="text inputcaption"><b><?= _("Email")?></b></div>
<input type="email" name="username" value="<?=$objMobile->GetEmail()?>">
</div>
</form>
在发布请求中调用文件xyz.php
时,$_SESSION
数组将变为空。请注意在打印会话数组之前session_start();
中已提供xyz.php
。为什么会话数组本身变空。
xyz.php的代码:
<?php
session_start();
print "<pre>";
print_r($_SESSION);
print "<post>";
?>
请找到通过phpinfo();
获得的会话设置|---------------------------------|---------------------|---------------------|
| Session Support | enabled | |
| Registered | save handlers | files user |
| Registered | serializer handlers | php php_binary wddx |
| | | |
|---------------------------------|---------------------|---------------------|
| Directive | Local Value | Master Value |
|---------------------------------|---------------------|---------------------|
| session.auto_start | Off | Off |
| session.bug_compat_42 | On | On |
| session.bug_compat_warn | On | On |
| session.cache_expire | 180 | 180 |
| session.cache_limiter | nocache | nocache |
| session.cookie_domain | no value | no value |
| session.cookie_httponly | Off | Off |
| session.cookie_lifetime | 0 | 0 |
| session.cookie_path | / | / |
| session.cookie_secure | Off | Off |
| session.entropy_file | no value | no value |
| session.entropy_length | 0 | 0 |
| session.gc_divisor | 100 | 100 |
| session.gc_maxlifetime | 1440 | 1440 |
| session.gc_probability | 1 | 1 |
| session.hash_bits_per_character | 4 | 4 |
| session.hash_function | 0 | 0 |
| session.name | PHPSESSID | PHPSESSID |
| session.referer_check | no value | no value |
| session.save_handler | files | files |
| session.save_path | C:\Windows\Temp | C:\Windows\Temp |
| session.serialize_handler | php | php |
| session.use_cookies | On | On |
| session.use_only_cookies | Off | Off |
| session.use_trans_sid | 0 | 0 |
|---------------------------------|---------------------|---------------------|
启用error_reporting后,会出现以下警告:
Warning: Unknown: open(C:\Windows\Temp\sess_1037ca26d3ebb62017eddc9cbfb107e2, O_RDWR) failed: Invalid argument (22) in Unknown on line 0
Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (C:\Windows\Temp) in Unknown on line 0
答案 0 :(得分:0)
我将您的代码段转换为工作代码,它就像魅力一样运行。 请提供完整的非工作示例,以便我们为您提供帮助。
a.php只会:
<?php
session_start();
$_SESSION['fromPanel'] = "abcd";
?>
<form method="post" action="./b.php">
<input type="email" name="username" value="john@example.com">
</form>
b.php:
<?php
session_start();
var_dump( $_SESSION['fromPanel'] );
var_dump( $_POST['username'] );
echo '<a href="./_test.php">back to form</a>';
发送表单后的结果输出(输入输入):
string 'abcd' (length=4)
string 'john@example.com' (length=16)
back to form
N.B:使用<label for="id-of-form">caption</label>
代替<div class="text inputcaption"></div>
答案 1 :(得分:0)
更多要检查的事项:
session_regenerate_id()
之后致电session_start()
,以确保它不是一些让您遇到麻烦的旧测试内容。phpinfo();
输出。error_reporting(E_ALL)
。答案 2 :(得分:-2)
如果要在header.php或common.php等所有视图中包含公共文件,只需在顶部写入session_start()。