开发者

How can I assign a session key with Javascript?

I have a PHP program, called login.

When the user passes something, like email and password, login.php 开发者_JS百科will return a session key to the user, if the login succeeds.

And I have JavaScript code to call this function to do the login.

How can I store this session key to identify whether the user is logged in?


The session is stored in a cookie by the server.
You don't need to do anything on the client.


a session is serverside.. not clientside.. so you cant set it through js


Sessions are declared manually like this:

$_SESSION['user'] = $_POST['username']; // or any other variable

You can then check on the other pages with PHP like this:

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

    //do this if true

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜