**Sessions or Cookies
Hi,
As the title of the topic says... I'm working on a project and I need to make a login system for an admin panel. And I'm not sure which one to use. Sessions or cookies?
And an other question. I managed to make it so the login creates a coockie of the username and IP combined. But I don't know how I can call it. Since
Here's my Login code that creates the cookies:
class auth {
function user_info_check( $username, $password ) {
global $db;
$sql = "
SELECT *
FROM users
WHERE username = '".$username."'";
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
if ( $result->num_rows < 1 )
die('Account dosen\'t exists');
$row = $result->fetch_assoc();
$pass1 = $row['password'];
$user1 = $row['username'];
$permission = $row['permission'];
if ( $username != $user1 ) {
die('Account dosen\'t exists');
}
if ( $password != $pass1 ) {
die('Wrong Password');
}
return array($username,$permission);
}
function login() {
global $username, $password;
// Returns the User's Username and Permission
$info = $this->user_info_check($username,$password);
setcookie($info[0]."-permission", $info[1], time()+3600);
setcookie("user-".$info[0], $username, time()+3600);
}
}
The user_info_check() uses the username and password from the login form, to get the requested data, which is the username and permission.
But my problem is... if I create the session named "user-Andor" for example, Andor is the username, How can I call it if I don't have the username saved anywhere?
Thanks!