7
I would like to know how I can complement the code below so that if the user is logged in there is no other person to access the restricted area with the same login and password when the user who used that access is active. So that if it closes the browser or logout the section is destroyed thus freeing access to that account.
Along with placing a remember button on the login form panel.
Follows below the Mysql along with the codes.
Mysql
CREATE TABLE IF NOT EXISTS `membros` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`login` char(20) NOT NULL DEFAULT 'admin',
`autor` varchar(20) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT 'Ryumaru',
`senha` char(255) NOT NULL DEFAULT 'admin',
`idade` int(2) NOT NULL DEFAULT '0',
`email` varchar(255) NOT NULL DEFAULT '[email protected]',
`cargo` enum('Adminstrador','Editor','Upload') NOT NULL DEFAULT 'Adminstrador',
`data_cadastro` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`data_ultimo_login` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`arquivo_data_cad` date NOT NULL DEFAULT '2014-05-03',
`arquivo_hora_cad` time NOT NULL DEFAULT '11:11:11',
`ativado` enum('0','1') NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `membrosDados` (`id`,`login`,`senha`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
check.php
<?php
session_start(); // Inicia a session
include "config.php";
$login = $_POST['login'];
$senha = $_POST['senha'];
if((!$login) || (!$senha)){
echo "<script>window.alert('Por favor, todos campos devem ser preenchidos!');</script>";
include "index.php";
}
else{
$senha = md5($senha);
$sql = mysql_query("SELECT * FROM membros WHERE login='{$login}' AND senha='{$senha}' AND ativado='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
$_SESSION['id'] = $id;
$_SESSION['login'] = $login;
$_SESSION['autor'] = $autor;
$_SESSION['email'] = $email;
mysql_query("UPDATE membros SET data_ultimo_login = now() WHERE id ='{$id}'");
header("Location:/admin/inicio/");
}
}
else{
echo "<script>window.alert('Acesso negado tente nova mente');</script>";
include "index.php";
}
}
?>
Function.php
<?php
function session_checker(){
if(!isset($_SESSION['id'])){
header ("Location:/admin/");
exit();
}
}
function verifica_email($EMAIL){
list($User, $Domain) = explode("@", $EMAIL);
$result = @checkdnsrr($Domain, 'MX');
return($result);
}
?>
Protect the sections. by checking if the user is logged in I place this at the beginning of the page
<?php include("config.php");
session_start();
include "functions.php";
session_checker(); ?>
Logout.php
<?php
session_start();
if(!isset($_REQUEST['logmeout'])){
echo "Você realmente deseja sair da área restrita?<br />";
echo "<a href=\"logout.php?logmeout\">Sim</a> | <a href=\"javascript:history.go(-1)\">Não</a>";
}
else{
session_destroy();
include "index.php";
}
?>
Tried to put an active field in the database? When logging in, check if it is 1, this logged in, if not arrow 1 to leave as logged in.. if it is already with 1, it does not allow a new login, and when leaving, put the asset as zero, to release accesses... just need to see the question when close the browser, to do this automatically also.
– Sr. André Baill
This is exactly what I need in case the question of deleting if the page is closed for security or has in the case a length of time. I edited the question.
– Striffer
Try to do as I told you... to see, and here we will see if someone knows how to do when closing the browser, if it gives an active set = 0, to dislodge and free access to others
– Sr. André Baill
More in case only one doubt whether the user who logged in close the browser without undoing to apply the destruction of Session as well as update value 0 the user would not be prevented from entering in the same way as another user who is trying to use the same login and password ?
– Striffer
That’s what I told you... we have to see here with the staff if someone is able to help us try to solve... if it closes without leaving, I think we would have to give an active set 0, at the time of closing the browser... there must be some jquery that does this...
– Sr. André Baill
I think I found what I need look just http://answall.com/questions/33867/realizar-a%C3%A7%C3%A3o-to-close-browser
– Striffer
Okay, I guess that would be it...
– Sr. André Baill
I published a reply... if it is useful, give an acceptance. Thanks!
– Sr. André Baill