开发者

Question about user system, specifically sessions with PHP

开发者 https://www.devze.com 2022-12-18 07:53 出处:网络
I was reading this article: http://www.devarticles.com/c/a/PHP/Creating-a-Membership-System/2/ I am not sure if I understand sessions properly. Do I hav开发者_Go百科e to start a session for each mem

I was reading this article: http://www.devarticles.com/c/a/PHP/Creating-a-Membership-System/2/

I am not sure if I understand sessions properly. Do I hav开发者_Go百科e to start a session for each member protected page? or do I just have to create one session and check if the user is in a session on each and evey page? how would I do that? Examples apprecited! :)


you (usally) don't really create a session. You just session_start(); on beginning of EVERY page and assign data to $_SESSION.

EDIT:

PHP sessions are not really "sessions", they're just containers of data.

When users logs in, you assign to session for example:

$_SESSION['loggedin'] = '1';

And on every page you check that:

if($_SESSION['loggedin'] !== '1')
{
   exit;
}

// your stuff

very simple.

0

精彩评论

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

关注公众号