php 防止会员劫持,PHP中正确的会话劫持预防

我知道这个话题已经讨论 了很多 ,但是我还有一些具体问题仍未得到解答。例如:

// **PREVENTING SESSION HIJACKING**

// Prevents javascript XSS attacks aimed to steal the session ID

ini_set('session.cookie_httponly', 1);

// Adds entropy into the randomization of the session ID, as PHP's random number

// generator has some known flaws

ini_set('session.entropy_file', '/dev/urandom');

// Uses a strong hash

ini_set('session.hash_function', 'whirlpool');

// **PREVENTING SESSION FIXATION**

// Session ID cannot be passed through URLs

ini_set('session.use_only_cookies', 1);

// Uses a secure connection (HTTPS) if possible

ini_set('session.cookie_secure', 1);

session_start();

// If the user is already logged

if (isset($_SESSION['uid'])) {

// If the IP or the navigator doesn't match with the one stored in the session

// there's probably a session hijacking going on

if ($_SESSION['ip'] !== getIp() || $_SESSION['user_agent_id'] !== getUserAgentId()) {

// Then it destroys the session

session_unset();

session_destroy();

// Creates a new one

session_regenerate_id(true); // Prevent's session fixation

session_id(sha1(uniqid(microtime())); // Sets a random ID for the session

}

} else {

session_regenerate_id(true); // Prevent's session fixation

session_id(sha1(uniqid(microtime())); // Sets a random ID for the session

// Set the default values for the session

setSessionDefaults();

$_SESSION['ip'] = getIp(); // Saves the user's IP

$_SESSION['user_agent_id'] = getUserAgentId(); // Saves the user's navigator

}

所以,我的问题是

做ini_set的提供足够的安全性?

可以保存用户的IP和导航器,然后在每次加载页面时进行检查以检测会话劫持吗?这有什么问题吗?

使用session_regenerate_id()正确吗?

使用session_id()正确吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值