Jump to content

PHP session authentication question


Buglish

Recommended Posts

Hi I have made this basic model for all pages in my website.
-Will this be too much overhead processing and improper space utilization?
-Is this a terrible way to authenticate the user and have different classes of login functions?

[code]

<?php session_start();?>
<html>
    <head>
        <title>Title</title>
    </head>
    <body>
       
    <?php
    include "../bin/db.php";
    $pagelink = $_GET['pagelink'];
    $submit = $_POST['submit'];
    $username ="";
    $password="";
    $loginType=0;   
   
    function Learner()
    {
        global $submit,$pagelink,$username,$password,$loginType;   
    }
   
    function Guest()
    {
        global $submit,$pagelink,$username,$password,$loginType;       
    }
   
    function Instructor()
    {
        global $submit,$pagelink,$username,$password,$loginType;
    }
   
    function Admin()
    {
        global $submit,$pagelink,$username,$password,$loginType;   
    }
   
    // -----------Start of Main Code--------
        if (!isset($_SESSION)) //Create or retrieve session variables
        {         
          $_SESSION['username']="Guest";
          $_SESSION['password']="Guest";
          $_SESSION['logintype']=0;
          echo  $_SESSION['username'];
          echo  $_SESSION['password'];
        }
        else
        {
            ?>
            You are Logged on.<br>
            <?php
          $username = $_SESSION['username'];
          $password = $_SESSION['password'];
          $loginType = $_SESSION['logintype'];   
        }
       
        switch($loginType)
        {
            case 0 : Guest(); break;
            case 1 : Learner(); break;
            case 2 : Instructor(); break;
            case 3 : Admin(); break;
            default : Guest(); break;
        }           
        ?>             
    </body>
</html>
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.