PHP Session Management - Basics -


i have been trying learn session management php... have been looking @ documentation @ www.php.net , looking @ these examples. going on head....

what goal when user logs in... user can access reserved pages , and without logging in pages not available... done through sessions material on internet difficult learn...

can provide code sample achieve goal can learn or reference tutorial...

p.s. excuse if have been making no sense in above because don;t know stuff beginner

  • every pages should start session_start()
  • display login form on public pages minimum login credentials (username/password, email/password)
  • on submit check submitted data against database (is username exists? » password valid?)
  • if so, assign variable $_session array e.g. $_session['user_id'] = $result['user_id']
  • check variable on every reserved page like:

    <?php if(!isset($_session['user_id'])){ //display login form here }else{ //everything fine, display secret content here } ?> 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -