How do I protect a page only for logged users?

前端 未结 4 1275
南旧
南旧 2020-12-11 02:59

I created a login form that works great. But I realized the page my user is directed to can still be accessed by anybody. How do I protect the page being accessed only vie

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 03:31

    Every of your page should start with

    session_start();
    

    and you should not be using session_register( "variablename" ) as of PHP version 4.2, use

    $_SESSION["variable"] = value;
    

    so example page with is-logged-it checking would be:

    
    

    and logging-in script:

    
    

提交回复
热议问题