Jump to content


Photo

PHP session authentication question


  • Please log in to reply
2 replies to this topic

#1 Buglish

Buglish
  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationSouth Africa

Posted 22 September 2006 - 09:32 AM

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?


<?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>


#2 steveclondon

steveclondon
  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 22 September 2006 - 09:37 AM

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 .

#3 Buglish

Buglish
  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationSouth Africa

Posted 22 September 2006 - 09:47 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users