Jump to content

[SOLVED] Checking login info?


Norsk.Firefox

Recommended Posts

<?php
session_start();

$loggedIn = False;

// Either not logged in or session expired 
if( empty($_SESSION['user']) ) {
    if( isset($_COOKIE['user']) ) {
        $data = unserialize($_COOKIE['user']);
        // Assumes loginUser escapes variables...
        if( loginUser($data['user'],$data['pass']) ) {
            $_SESSION['user'] = $data;
            // Now logged in
            $loggedIn = True;
         }
     }
} else $loggedIn = True;
?>

 

When they actually do login, assign $_COOKIE['user'] serialized data of the $_SESSOION['user']. Users can modify cookies, but with the login check you can see if the cookie is valid or not.

 

Link to comment
Share on other sites

you do your DB check and if the user is able to log in just set a session to their session id

 

$sessionID = SESSION_ID();

$_SESSION['sid'] = $sessionID."staff";

 

then check on the top of each page that you want protected by checking that value

 

session_start();

        $sessionID = SESSION_ID();

    if ($_SESSION['sid'] != $sessionID."staff") {

    header("Location: http://www.yoururl.com");

}

 

or something like that, code above is from the top of my head but you should get the meaning :)

Hope it was some help :)

 

Stephen

 

 

 

 

Link to comment
Share on other sites

Especially if they edit their profile.  You want to make sure they are in fact editing their own and have no way to edit someone elses.

 

I just did this today on one of my pages, and it was a bit of a challenge to make sure they are only allowed to edit their own profile.  Takes a little bit of thinking and logic.

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.