用于用户身份验证的PHP会话 [英] PHP session for user authentication

查看:62
本文介绍了用于用户身份验证的PHP会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将使用Cookie和会话来标识用户.因此,仅当用户选择了不要记住我"选项时,才会使用会话.我在网站每页的顶部都包含标识文件.用户会话类似于 $ _ SESSION ['user']

I'm going to use cookies and sessions to indentify the user. So, sessions will be used only when user chose the 'Don't remeber me' option. I include the identification file in the top of every page of website. User's session looks like $_SESSION['user']

比我的问题还重要:

我是否必须将验证码放置在 session_start()指令中?我之所以这样问,是因为每次使用此指令时都会创建新的会话.

Must I place to the authentication file session_start() instruction? I asked it because new session creates every time I use this instruction.

更新 http://pastebin.com/Nh3zj6mR 用户识别脚本

推荐答案

是的,您必须将 session_start()放在每个 php 页面的顶部(任何输出之前)已生成,因此无需发送任何标头)告诉php接受/启动会话,期望您的 php.ini 已设置,会话自动启动.

Yes, you have to place session_start() at top of every php page (before any output was generated, no headers must have sent before) to tell php to accept / start session, expect your php.ini is setup, that sessions start automatic.

之所以问,是因为每次使用此指令都会创建新的会话.

I asked it because new session creates every time I use this instruction.<<

这暗示着您的浏览器忽略(禁止)会话cookie

That is a hint, that your browser ignore (disallow) session cookies

这篇关于用于用户身份验证的PHP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆