会话保持 会话共享
Sessions can be extremely useful when developing content that requires the ability to be able to carry over from page to page without the use of posting form data. An application that commonly makes use of PHP sessions are authentication and registration systems.
当开发的内容需要能够在不使用过帐表单数据的情况下从一个页面继续到另一个页面时,会话非常有用。 身份验证和注册系统是通常使用PHP会话的应用程序。
Here, in this tutorial, I will attempt to layout the basics of a simple session with examples and descriptions that will support the examples.
在这里,在本教程中,我将尝试通过示例和支持示例的描述来布局简单会话的基础。
Probably the greatest stumbling block that will almost invariably get in the way of every new PHP developer is the issue of creating a new session, but with the error Cannot send session cache limiter - headers already sent
几乎每一个新PHP开发人员都会遇到的最大绊脚石是创建新会话的问题,但出现错误
This error is almost always due to one very simple mistake and it's solution is just as simple to resolve. So, let's start by showing the code snippet that will cause this error followed by it's simple solution so that you can get rolling in creating working and useful sessions in PHP.
此错误几乎总是由一个非常简单的错误引起的,并且其解决方案也很容易解决。 因此,让我们首先显示将导致此错误的代码段,然后再给出简单的解决方案,以便您可以滚动创建使用PHP的有效会话。
1.创建一个test.php文件 (1. Create a test.php file)
使用您喜欢的编辑器,创建一个名为test.php的文件并将其保存到本地开发目录(或Windows用户的文件夹)2.添加PHP代码 (2. Add PHP code)
现在,您要向该文件添加以下代码;'Add a space here or any character'
<?php
session_start();
?>
3.保存并上传您的作品 (3. Save & Upload your work)
现在,只需保存文件并将其上传到Web服务器即可。 我假设您对这方面有很好的了解。完成上述步骤后,现在继续从浏览器中的Web服务器调用test.php,您应该会看到类似的错误报告上文提到的。As you can see from the code snippet. There is a line of non-PHP page content above the opening
正如您从代码片段中看到的那样。 开头上方有一行非PHP页面内容
Fixing this problem is just as simple as the problem itself. Simply remove the entire line before the opening
解决此问题与解决问题本身一样简单。 只需在打开前去除整条线
And voila! Problem solved!
瞧! 问题解决了!
This was a test article submission and was meant to aid in the beta testing of this new feature.
这是一份测试文章,旨在帮助对该新功能进行beta测试。
翻译自: https://www.experts-exchange.com/articles/208/Simple-PHP-Session-Tutorial.html
会话保持 会话共享