PHP prevents session pinning attacks

Source: Internet
Author: User
Tags session id

Issue: You want to ensure that the app is not subject to a session pinning attack, which means that the attacker forces the user to use a predefined session ID.

Solution: A session cookie is required but the session identifier is not appended to the URL, and a new session ID is generated frequently:

1<?PHP2 Ini_set(' Session.use_only_cookies ',true);3 //prevent session pinning attacks4 Session_Start();5 6 //generate a new phpsessid every 30 seconds7 if(!isset($_session[' generated ']) ||$_session[' Generated '] < ( Time()-30) ) {8     Echo"Create<br/>";9     //generate a new session IDTen     session_regenerate_id(); One     $_session= [ A' User ' = ' lemon ', -' Generated ' = Time() -     ]; the  -}Else { -     Echo"Ok<br/>"; -     Print_r($_session); +}

This approach basically eliminates the risk of session pinning attacks, and it is difficult for an attacker to get a valid session ID because the session ID will change frequently.

PHP prevents session pinning attacks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.