Jump to content

Archived

This topic is now archived and is closed to further replies.

Buglish

PHP session authentication question

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]

Share this post


Link to post
Share on other sites
Is it working, if so looks fine to me. I have several sites that run a few pages of different information before it gets into doing anything I can't see this causing a major load on the server at all, if that is what you mean .

Share this post


Link to post
Share on other sites
Hi,
Yes I was worried that my first design of sessions looks a bit flimsy or not robust enough.
I am new to PHP so I am not sure how to approach this matter.

Thanks for the Info.

Share this post


Link to post
Share on other sites

×

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.