Welcome Guest, Not a member yet? Register   Sign In
Loginsystem with sessions.
#1

[eluser]Jesse2303[/eluser]
Hi all, back again Big Grin

I've got a question. How I make a good login with sessions ?
What files I need to update and what sort of query I need to use.

How I update my menus and how I write them in a view file ?.

Before
Code:
<?php
if(isset($_SESSION['user'])) {
?>
ADMIN - NEWS PICTURES LINKS BLOGS
<?php
} else {
?>
You're not logged in.
<?php
}
?>

After
Code:
Give me please :)

Thanks a lot.
See also this topic...
#2

[eluser]Colin Williams[/eluser]
Well, you should probably create or use a more robust library to handle such systems. I would recommend doing more than simply checking for the existence of a session variable. CodeIgniter includes a Session library, and there are several improvements in the Wiki to consider using as a base for your login system. The user library I use has an access method that lets you easily perform these types of checks:

Code:
if ($this->user->access())
{
  // Do something for any logged in user
}
if ($this->user->access('modify content'))
{
  // Do something for any user with 'modify content' permission
}
if ($this->user->access(NULL, 'user/login'))
{
  // Do something for any logged in user, redirect to 'user/login' otherwise
}

As you can see, the method reads well and provides multiple uses to streamline code. I'd suggest trying something similar.
#3

[eluser]Jesse2303[/eluser]
[quote author="Colin Williams" date="1214265746"]Well, you should probably create or use a more robust library to handle such systems. I would recommend doing more than simply checking for the existence of a session variable. CodeIgniter includes a Session library, and there are several improvements in the Wiki to consider using as a base for your login system. The user library I use has an access method that lets you easily perform these types of checks:

Code:
if ($this->user->access())
{
  // Do something for any logged in user
}
if ($this->user->access('modify content'))
{
  // Do something for any user with 'modify content' permission
}
if ($this->user->access(NULL, 'user/login'))
{
  // Do something for any logged in user, redirect to 'user/login' otherwise
}

As you can see, the method reads well and provides multiple uses to streamline code. I'd suggest trying something similar.[/quote]

Thanks for this part but I need to add something in the config/autoload.php ?
And how I build the loginfunction ?

See also this topic...
#4

[eluser]Colin Williams[/eluser]
The code I included is only an example of how I use a system I developed. It's not standard CI stuff.

You might not need to add anything to autoload.php... But I suggest using the Session class to handle sessions. It's all in the User Guide. I would also suggest storing user data in a database, so you'll need to use the Database class. You'll want to encrypt sensitive data like passwords, so you'll want to make use of the Encryption class.

Quote:And how I build the loginfunction ?

I'm not sure if you're expecting pre-rolled code or what, but if so, check out the Wiki or Ignited Code forum for user authentication/authorization libraries. There are several out there, but they're all needlessly bloated IMO.

If you want something even more automated/pre-rolled for you, look into something with a full user system built in, like Drupal.
#5

[eluser]Jesse2303[/eluser]
Hi,

My Login works perfectly. Only my menu won't update.

Login Function
Code:
function login() {

        if(isset($_POST['submit'])) {
        
        $hashed = $_POST['wachtwoord'];
        
        if($_POST['name'] == "Gebruiker" or $_POST['wachtwoord'] == "Wachtwoord") {
                
                echo 'U bent iets vergeten invullen';
                
         } else    {
                
            
            $query = $this->db->query("SELECT * FROM admin WHERE gebruiker = '" . mysql_real_escape_string($_POST['name']) . "' AND wachtwoord = '".$hashed."' LIMIT 1");
            
            $this->session->set_userdata('login', '1');
            $this->session->set_userdata('gebruiker', $_POST['name']);
            
                    
                // Give a succeed message
            
                }
        }
        
        
            $data['title'] = 'iAdmin';
            $data['copyrights'] = 'Imagine Works 2008 - 20..';
            
            
            
            $this->load->view('login_view', $data);
            
    }

Autoload
Code:
/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your system/application/libraries folder.
|
| Prototype:
|
|    $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/

$autoload['libraries'] = array('database', 'session');

Menu ( words in dutch if you don't mind
Code:
<?php
        if(isset($_SESSION['gebruiker'])){
    ?>
            admin     <?=anchor('dashboard', 'dashboard');?> begin
                  - <?=anchor('login', 'uitloggen');?>  
            modules <?=anchor('pics', 'afbeeldingen');?>  
                  - <?=anchor('nieuws', 'nieuws');?>
    <?php
        }
            else
        {
    ?>
        gast  <?=anchor('main', 'begin');?>
            - &lt;?=anchor('login', 'login');?&gt;</a>
            - &lt;?=anchor('contact', 'contact', '');?&gt;</a>
    &lt;?php
        }
    ?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB