0
I have a website ready, but I want my program to check the user login on the site. Basically it can register in both and access both with the same user(The site and the system uses the same database). But I’m not getting this system check.
<?php include "./config/global.php";
error_reporting(E_ALL);
if(isset($_SESSION['login23'])){
echo '<script>location.href="principal.php";</script>';
}
?>
<?php include "php/head.php";?>
<title>Entrar - <?php echo $titulocf;?></title>
<style type="css">
.text-transform: lowercase;
</style>
<audio src="" autoplay></audio>
</head>
<body>
<form action="" id="validate" class="form-horizontal" method="POST" role="form">
<?php
if(isset($_POST['enviar_cadastro']) && $_POST['enviar_cadastro'] == 'envia'){
?>
<div style="display:none;">
</div>
<?php
$login = $_POST['login'];
$login = antiSQL($login);
$senha = $_POST['senha'];
$senha = antiSQL($senha);
$query1 = "SELECT * FROM clientes WHERE login='$login' AND senha='$senha' AND suspenso='nao'";
$query1 = mysql_query($query1);
$total1 = mysql_num_rows($query1);
$select = "SELECT * FROM clientes WHERE login='$login'";
$result = mysql_query($select);
while($l = mysql_fetch_array($result)){
$suspenso = $l['suspenso'];
}
if($total1 == "1"){
$_SESSION['login23'] = $login;
$login23 = $_SESSION['login23'];
$log = "Usuario entrou no Painel de Controle !";
$ip = $_SERVER['REMOTE_ADDR'];
$hora = date("h:i:s");
$data = date("d/m/Y");
$genero = "entrou";
$registro = "$data ás $hora";
$insert = "INSERT INTO log (log, ip, data, autor, genero) VALUES ('$log', '$ip', '$registro', '$login', '$genero')";
$resultado = mysql_query($insert) or die ("");
echo '<script language= "JavaScript">location.href="principal.php"</script>';
}if($total1 == "0"){
$login_error="<b>Login</b>, ou <b>Senha</b> incorretos !";
}
}?>
<div class="login-container animated fadeInDown">
<div class="loginbox bg-white">
<div class="loginbox-title"><span class="text-info">MM</span><span>onitor</span>
</div>
<div class="loginbox-social">
<div class="social-title ">Entre na sua conta</div>
</div>
<div class="loginbox-or">
<div class="or-line"></div>
</div>
<?php if(isset($login_error)){
if ($suspenso == "sim") {
echo '<div class="alert alert-danger fade in radius-bordered alert-shadowed">
<button class="close" data-dismiss="alert">
×
</button>
<i class="fa-fw fa fa-times"></i>
<strong>Erro</strong> Hotel suspenso.
</div>';
}
elseif (empty($login)) {
echo '<div class="alert alert-danger fade in radius-bordered alert-shadowed">
<button class="close" data-dismiss="alert">
×
</button>
<i class="fa-fw fa fa-times"></i>
<strong>Erro</strong> Informe um usuário e senha.
</div>';
}else{
echo '<div class="alert alert-danger fade in radius-bordered alert-shadowed">
<button class="close" data-dismiss="alert">
×
</button>
<i class="fa-fw fa fa-times"></i>
<strong>Erro</strong> Usuário ou senha incorretos.
</div>';
}
} ?>
<div class="loginbox-textbox">
<input type="text" name="login" autocomplete="off" class="form-control" placeholder="Usuário" />
</div>
<div class="loginbox-textbox">
<input type="password" name="senha" class="form-control" placeholder="Senha" />
</div>
<div class="loginbox-forgot">
<a href="senha.php">Esqueçeu sua senha?</a>
</div>
<div class="loginbox-submit">
<input type="hidden" name="enviar_cadastro" value="envia" /> <input type="submit" class="btn btn-primary btn-block" value="Entrar">
</div>
</div>
</form>
<div class="logobox">
</div>
</div>
</body>
</html>
string usuario = "admin";
string senha = "admin";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "login=" + usuario;
postData += ("senha=" + senha);
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://localhost/");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
StreamReader reader = new StreamReader(newStream);
newStream.Close();
MessageBox.Show(reader.ToString());
What’s going on? It’s coming to the server in the login method?
– Aline
I’m using the code in the button event, but it just doesn’t happen, I tried how to get(I changed the form too) even so don’t login and no error appears.
– Rickafds
Stop at some bp in this method? It enters the method, is it? But it does call the other project checking the login?
– Aline
If I run it line by line it will run the form, but when I click the button nothing happens. I want you to click it enter the link and log in and return if it was successful
– Rickafds
Enter which link? Your form has no action. Qndo Ubmita goes where?
– Aline
In the localhost link, when Submita has the php code that checks if the login is correct and if it is ok, it enters the localhost dasboard.php
– Rickafds
Your question is not very clear to me. I don’t understand it. This code that you put in c# means q if it
– Aline
I updated the post code
– Rickafds