0
I have the following error in the captcha:
Notice: Undefined index: captcha in C: xampp htdocs darknetwork index.php on >line 7
and also it is only returning me the Else even if you give a F5 on the page, the session_start();
is already in config.php
index php.
<?php require 'config.php'; require 'classes/usuarios.class.php'; $ip = $_SERVER["REMOTE_ADDR"]; $u = new Usuarios; if($_SESSION['captcha'] == $_POST['captcha']) { if(isset($_POST['email']) and !empty($_POST['email'])) { $email = addslashes($_POST['email']); $senha = addslashes($_POST['senha']); if($u->login($email, $senha)) { header("Location: central.php"); } else { ?> <div align="center" class="alert alert-danger"> E-mail e/ou Senha incorretos, tente novamente ! </div> <?php } } } else { ?> <div align="center" class="alert alert-danger"> Captcha esta incorreto ! </div> <?php } ?> <!DOCTYPE html> <html> <head> <title>Dark Network</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="assets/css/style.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> </head> <body> <div class="login-page"> <div class="form"> <div style="color:#fff;" class="h4"> ÁREA DE LOGIN - DARK NETWORK </div> <form class="login-form" method="post"> <hr> <input type="email" name="email" placeholder="E-mail" required=""/> <input type="password" name="senha" placeholder="Senha" required=""/><br/><br/> <img src="captcha.php" alt="Código captcha"/><br/><br/> <input type="text" name="captcha" placeholder="Digite o código" required=""/><br/> <button type="submit"><span>Entrar</span></button> <hr> <p class="message">Não é registrado ? <a href="cadastrar.php">Cadastre-se aqui.</a></p> <p style="color:#999;">Desenvolvido por: Weltec</p> </form> </div>
`
captcha.php
<?php session_start(); $codigoCaptcha = substr(md5(time().rand(0,999)), 0, 9); $_SESSION['captcha'] = $codigoCaptcha; $imagemCaptcha = imagecreatefrompng("fundocaptch.png"); $fonteCaptcha = imageloadfont("anonymous.gdf"); $corCaptcha = imagecolorallocate($imagemCaptcha, 0, 115, 50); imagestring($imagemCaptcha, $fonteCaptcha, 15, 5, $codigoCaptcha, $corCaptcha); imagepng($imagemCaptcha); imagedestroy($imagemCaptcha); ?>
Notice: Undefined index: captcha in C:\xampp\htdocs\darknetwork\index.php on >line 7
this is because php is looking for a value for the validation of your captcha even before you even type in the form to solve this problem putif(isset($_POST['submit'])){//codigo de validação aqui}
and also you will have to give a name for your Submit input<button type="submit" name="submit"><span>Entrar</span></button>
– Adriano Back
another detail its validation is incorrect because its
$_SESSION['captcha']
is saving a value in MD5 and your $_POST['captcha'] not when the two are compared will never be valid because one will always be different from the other even if the user type correctly in the form so you should color this way in the beautiful codeif($_SESSION['captcha'] == MD5($_POST['captcha'])) {
– Adriano Back
but I would recommend you use the google reCaptcha is more robust and safer https://answall.com/questions/59952/howto implementar-recaptcha-do-google-no-meu-site
– Adriano Back