Home > Backend Development > PHP Tutorial > javascript - 登陆成功后,右上角显示用户名,cookie里存了,如何读出来放到哪里,求案例

javascript - 登陆成功后,右上角显示用户名,cookie里存了,如何读出来放到哪里,求案例

WBOY
Release: 2016-06-06 20:44:38
Original
2209 people have browsed it

登陆成功后,右上角显示用户名,cookie里存了,如何读出来放到哪里,求案例

回复内容:

登陆成功后,右上角显示用户名,cookie里存了,如何读出来放到哪里,求案例

http://coolshell.cn/articles/5353.html
好好看这篇文章吧,看看实现机制,你就知道如何取用户名了。

你是要问如何从cookies里面获取用户名么?

<code><div id="user"></div>
<script type="text/javascript">
var cookie = {
    get:function(str){
        var cookies = {};
        document.cookies.split(';').forEach(function(item){
            var c = item.split('=');
            cookies[c[0]]=c[1];
        });
        return cookies[str] || "";
    }
}
document.querySelector("#user").innerHTML = cookie.get("username");
</script>
</code>
Copy after login

不过好像一般的思路都是直接PHP输出$username到页面的说。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template