Login Logout System

Discussion in 'PHP' started by Subikar, May 22, 2007.

?

Is this code is helpful for you ?

Poll closed May 21, 2008.
  1. YES

    2 vote(s)
    20.0%
  2. NO

    8 vote(s)
    80.0%
  1. #1
    Most of my friend asking me to send how I can write login logout system. For them and those who are in starting phase of php I have wrote a code so it will be useful for them.
    I am adding here the code :
    <?php
    // For Logout Simply call the function  FnLogOutUser()  this will work.
      $LoggedInLoggedOutClassObj = new LoggedInLoggedOutClass;
      $UserID = $LoggedInLoggedOutClassObj->FnCheckUserLoggedIn(); 
      if($UserID == '')
        {
            $UserID = 1;
            //At first fetch  the user_id from table and store in a array
            $UserIDInArray = array (
                                      'UserID'=>$UserID  
                                    );
            //Call this function to user login
               $LoggedInLoggedOutClassObj->FnLoginUser($UserIDInArray);
            
            
        }
      if($UserID != '')
        {
            //Do What ever logged in part you want do
            echo 'UserLoggedIn';
        }
      else 
        {
             // Open logged in form.
        }
      class LoggedInLoggedOutClass
        {
          function FnCheckUserLoggedIn()
              {
                 $UserID = isset($_COOKIE['YourDomainName'])?$_COOKIE['YourDomainName']:'';
                 return $UserID;
                  
              }
          function FnLogOutUser()
              {
                   setcookie ("YourDomainName","", time()-3600,"/");              
              }
          function FnLoginUser($UserIDInArray)
              {
                   setcookie("YourDomainName",$UserIDInArray['UserID'],time() + 3600,"/"); 
                   return TRUE;
              } 
    
            
        }
    ?>
    
    PHP:

     
    Subikar, May 22, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    This is REALLY not secure. I could log in as anybody by simply changing the value in the cookie. Or I could log in by simply sending a fake cookie not sent by your site, and log in without username or password.
     
    nico_swd, May 22, 2007 IP
  3. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Yes Nico_swd any one can logged in by editing the cookie. But this is for beginner those who want to understood.

    One thing can we do while creating cookie we will encrypt the user id and while fetching it we will decrypt it. I think this will secure then.
     
    Subikar, May 22, 2007 IP
  4. Mr D

    Mr D Peon

    Messages:
    35
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    not a good use of OOP. LoggedinLoggedOutClass is not really an object
     
    Mr D, May 22, 2007 IP
  5. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Not a good use of oop ? What does it means what you want to say ?:confused:
     
    Subikar, May 22, 2007 IP
  6. mrmonster

    mrmonster Active Member

    Messages:
    374
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #6

    Kinda silly method of authentication but using a class for it is just fine.

    You don't always need to store data in the object, you can use classes as namespaces and encapsulation, it helps with keeping things organized and easy to follow/debug in the future.
     
    mrmonster, May 22, 2007 IP
  7. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can't just post a bad code and say that it's for newbies so they can learn new stuff. Create a tutorial if you want to teach. I can unpack an open source project and I'm sure that I can see better code than this crap that you posted above which is also highly insecure.
     
    manilodisan, May 22, 2007 IP
  8. Gursimran

    Gursimran Well-Known Member

    Messages:
    1,385
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    160
    #8
    not secure but still very good for a simple one
     
    Gursimran, May 23, 2007 IP
  9. itrana123

    itrana123 Peon

    Messages:
    177
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    This code is not helpful for me and i think not for anyone else who know a little bit programming in PHP.
     
    itrana123, May 23, 2007 IP
  10. Gursimran

    Gursimran Well-Known Member

    Messages:
    1,385
    Likes Received:
    53
    Best Answers:
    0
    Trophy Points:
    160
    #10
    Lol who is saying it is not helpful. But it can be good. It is so simple. Need to be some more secure
     
    Gursimran, May 23, 2007 IP
  11. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #11
    Since when has a newbie jumped straight into classes :S

    The thought is still there though.
     
    adamjblakey, May 23, 2007 IP
  12. Subikar

    Subikar Active Member

    Messages:
    241
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #12

    For login and logout what type of easy code you want. If anyone want to make it secure he can do it as I discussed before by encrypting and decrypting then Whats the problem you are facing?:cool:

    I have not wrote full code OK in my next post I will make it secure. I think for beginner it is perfectly fine.
     
    Subikar, May 23, 2007 IP