本文介绍了PHP session_start()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

这到底是什么?

它是否基于cookie启动当前会话?从PHP网站得到了. PHP如何控制会话?如果我在用户打开登录页面时启动会话,那么我什至可以将该会话用于什么用途?我可以使用当前会话获取有关已登录用户的信息吗?

Does it start a current session based on cookies? Got that from the PHP website. How does PHP control the session? If I start a session when a user opens up my login page, what do I even use that session for? Can I use the current session to get info about the logged in user?

推荐答案

PHP会话系统使您可以安全地将数据存储在$_SESSION全局数组中.一个典型的示例是在用户输入密码时将其标识符存储在会话中:

The PHP session system lets you store securely data in the $_SESSION global array. A typical example is to store the user's identifier in the session when they type in their password:

if ($user = try_login($login, $password))
  $_SESSION['user'] = $user;

然后,您可以在所有其他页面上访问该信息:

Then, you can access that information on all other pages:

if (isset($_SESSION['user']))
  // logged in !
  echo user_name($_SESSION['user']);

数据存储在服务器上,因此没有被篡改的风险(另一方面,请注意磁盘的使用情况).

The data is stored on the server, so there is no risk of tampering (on the other hand, mind your disk usage).

启动会话使当前请求使用$_SESSION.如果这是用户的首次访问,则该数组将为空,并且将为您发送一个新的会话cookie.

Starting the session lets the current request use $_SESSION. If this is the user's first visit, the array will be empty and a new session cookie will be sent for you.

关闭会话只会阻止当前请求使用$_SESSION,但是数据会保留在下一个请求中.

Closing the session merely prevents the current request from using $_SESSION, but the data stays around for the next requests.

销毁会话将永远丢弃所有数据.在最后一次访问后的一定时间内(通常为30分钟左右),会话将被销毁.

Destroying the session throws away all the data, forever. The sessions are destroyed a certain duration after the last visit (usually around 30 minutes).

这篇关于PHP session_start()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:43