什么是创建一个PHP登录页面的最佳方式? [英] What is the best way to create a PHP login page?

查看:165
本文介绍了什么是创建一个PHP登录页面的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的PHP和正在寻找如何在PHP中实现身份验证的最佳实践。

I'm fairly new to PHP and am looking for some best practices on how to implement authentication in PHP.

我对Adobe的传播者,那让我生气的时候是使用Flex / Flash的登录屏幕的事情之一。所以,我想对使用HTML / PHP登录页面,然后传递会话信息到Flex -after-会议已定一个博客帖子/例子。

I'm an evangelist for Adobe and one of the things that annoys me is when people use Flex/Flash for the login screen. So I want to do a blog post/example on using an HTML/PHP login page and then passing the session information to Flex -after- the session has been set.

我还在包装我的头周围PHP需要建立一个有效的会话到底是什么以及它是如何设置的cookie。所以这具体涉及到的例子或资料将是非常有益的。

I'm still wrapping my head around exactly what PHP needs to create a valid session and how it sets cookies. So examples or information that specifically relate to that would be very helpful.

由于提前,

=瑞​​安ryan@adobe.com

=Ryan ryan@adobe.com

推荐答案

正如人们所说的,有相当多的以PHP创建强大而安全的认证系统,但基本面很容易掌握。

As has been said, there's quite a lot to creating a robust and secure authentication system in PHP, but the fundamentals are easy to grasp.

您想要做的第一件事就是调用在session_start()。一旦你做到了这一点,你可以使用设置会话变量 $ _ SESSION 超全局:

The first thing you want to do is call session_start(). Once you've done this you can get and set session variables using the $_SESSION superglobal:

session_start();
$_SESSION['foo'] = $foo;
$bar = $_SESSION['bar'];

一旦你做到了这一点,你可以设置登录时为一个成功的日志中的当前用户的详细信息,并让他们在持续的页面(记住使用之前调用在session_start 他们)。此外,在session_start 之前的任何内容发送到浏览器必须被调用。

Once you've done this you can set log in details for the current user upon a successful log in and have them persist over pages (remembering to call session_start before using them). Also, session_start must be called before any content is sent to the browser.

有安全问题需要考虑,如会话固定和饼干盗窃,但是。一种方法来固定会话,例如,在是使用权限提升到再生用户的会话ID PHP的 session_regenerate_id (或类似的东西)。

There are security issues to consider, such as session fixation and cookie theft, however. One approach to session fixation, for example, is to regenerate the user's session ID upon elevation of privileges using PHP's session_regenerate_id (or something like that).

借助 PHP安全联盟有很多有用的信息。

The PHP Security Consortium has lots of useful info.

Cookie可以使用 的setcookie 功能。

Cookies can be manipulated using the setcookie function.

这篇关于什么是创建一个PHP登录页面的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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