我正在为我所在城镇的当地企业创建一个目录。我允许每个企业在网站上创建一个个人资料,在那里他们可以上传联系信息,照片,他们在谷歌地图上的位置等。
我对php有很好的了解,但我不会接近行业标准。
我只是想找一些关于认证的业务是登录在管理页面上的一些建议。我目前的方式是,当他们的用户名和密码经过验证后,我会为他们创建一个会话:
$_SESSION['session_businessid']这基本上只是一个使用他们的企业ID的会话,该ID是从mySQL数据库中的企业表中获取的。
然后,在每个需要企业登录的页面上,我都会包含一个名为verify_logged_in.php的php文件,其中包含以下代码:
<?php
session_start();
if ($_SESSION['session_businessid'])
{
$BusinessID = $_SESSION['session_businessid'];
}
else
header ("location: /admin/login.php");
?>我只是想知道这种方法有多安全/不安全,有没有更好的方法?
发布于 2013-11-10 20:04:40
这是不够安全的,因为您将会话变量存储在默认的php会话中。您必须使用安全会话来保护被会话劫持或XSS攻击等误用的信息。您可以使用以下链接指导您如何创建安全的php会话- Create-a-Secure-Session-Managment-System-in-Php-and-Mysql。
或者,如果您想要一个更简单但安全性较低的会话,则可以使用以下代码:
sessions.php:
function sec_session_start() {
$session_name = 'sec_session_id'; // Set a custom session name
$secure = false; // Set to true if using https.
$httponly = true; // This stops javascript being able to access the session id.
ini_set('session.use_only_cookies', 1); // Forces sessions to only use cookies.
$cookieParams = session_get_cookie_params(); // Gets current cookies params.
session_set_cookie_params($cookieParams["lifetime"], $cookieParams["path"], $cookieParams["domain"], $secure, $httponly);
session_name($session_name); // Sets the session name to the one set above.
session_start(); // Start the php session
session_regenerate_id(); // regenerated the session, delete the old one.anypage.php:
include 'sessions.php';
sec_session_start();
//rest of the code.此外,您使用的登录方式将对企业存储信息的安全性产生影响。
https://stackoverflow.com/questions/19889373
复制相似问题