PHP会话文件为空
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP会话文件为空,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2061字,纯文字阅读大概需要3分钟。
内容图文
![PHP会话文件为空](/upload/InfoBanner/zyjiaocheng/660/72370430c6964147a7c83e9949b458ca.jpg)
我有启用了会话的PHP代码.会话文件是在tmp目录中创建的,但它为空,这就是为什么我的浏览器Internet Explorer和Chrome无法拾取会话并在页面上显示它的原因.
这是我的PHP代码.
第2页.
<html>
<body>
<form action="test3.php" method="post">
Username: <br><input type="text" name="username"></br>
<input type="submit" name = 'submit1' value= 'Login'>
</form>
</body>
</html>
第3页.
<?php
session_start();
?>
<html>
<body>
<?php
$username = $_POST['username'];
$_SESSION['username']= $_POST['username'];
echo "<br> Hi $username.</br>";
?>
<form action="test4.php" method="post">
<input type="submit" name = 'submit' value= 'click me'>
</form>
</body>
</html>
第4页.
<?php
session_start();
$username = $_SESSION['username'];
echo "<br> Hi $username.</br>";
?>
解决方法:
检查服务器的php.ini文件中的session.save_path.
您可以通过检查phpinfo()输出来查看现在设置的内容.
<?php
phpinfo();
?>
寻找会话块,看起来应该像这样;我的MAMP设置中的屏幕截图:
然后在您的php.ini中应该是这样的一大块配置:
; Argument passed to save_handler. In the case of files, this is the path
; where data files are stored. Note: Windows users have to change this
; variable in order to use PHP's session functions.
; As of PHP 4.0.1, you can define the path as:
; session.save_path = "N;/path"
; where N is an integer. Instead of storing all the session files in
; /path, what this will do is use subdirectories N-levels deep, and
; store the session data in those directories. This is useful if you
; or your OS have problems with lots of files in one directory, and is
; a more efficient layout for servers that handle lots of sessions.
; NOTE 1: PHP will not create this directory structure automatically.
; You can use the script in the ext/session dir for that purpose.
; NOTE 2: See the section on garbage collection below if you choose to
; use subdirectories for session storage
;
session.save_path = /Applications/MAMP/tmp/php
确保系统上确实存在该路径& Apache服务器可以写入的内容.如果该目录不存在或无法写入,请根据需要进行调整以匹配您的设置.
我发现this site在如何处理此类问题方面也有很多不错的信息.
内容总结
以上是互联网集市为您收集整理的PHP会话文件为空全部内容,希望文章能够帮你解决PHP会话文件为空所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。