douzhuan1467 2015-10-06 20:24
浏览 11
已采纳

是否存在公开显示会话ID的风险?

I want to know if someone knows my session id from HTML source, then they can hack my site?

For example, if i set a class in html like this <div class="class<?php echo session_id(); ?>"></div>

Then the HTML source code (that can be viewed from the browser) wil be <div class="class78345543545c344x"></div>

Is it risk?

  • 写回答

2条回答 默认 最新

  • doudianhuo1129 2015-10-06 20:33
    关注

    No matter what you store in a user's session, do not, i repeat, do not share the session id to someone other that the current user. Even though the session id is stored in a cookie (if enabled) or passed by query parameter in each request, no other person than the current user should be aware of somebody else's session id. Otherwise, identity phishing is wide open.

    As per one of your comments, you need a unique and random number until the session is finished, you could store it in session:

    session_start();
    if (!isset($_SESSION['myUniqueId'])) {
         $_SESSION['myUniqueId'] = rand(0, 99999999);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部