jarsantos Posted November 28, 2007 at 09:53 AM Report Share #150854 Posted November 28, 2007 at 09:53 AM Estou a tentar fazer um registo com validação por e-mail e imagem de segurança contra os bots. Está tudo a funcionar, as 2 unicas coisas que não estão a funcionar é o envio do e-mail e não aparece a imagem. A criação da imagem e a criação do código de activação estão a funcionar, só falta mesmo estes 2 pequenos problemas. Deve estar a faltar qualquer coisa, se alguem souber e quiser ajudar fica aqui o código: register.php <?php session_start(); $_SESSION['image_code'] = strtolower(substr(md5(time()), 0, 6)); $errors = FALSE; if (isset($_POST['submit'])) { if(!$_POST['nick']){ $errors = TRUE; echo "You need to introduce a nickname.";?><BR> <?php } elseif ($_POST['nick'][0] == ' ' | $_POST['nick'][strlen($_POST['nick'])-1] == ' '){ $errors = TRUE; echo "Your nickname can't start or end with a space.";?><BR> <?php } else { $nick = strtolower($_POST['nick']); } if(!$_POST['pass']){ $errors = TRUE; echo "You need to introduce a password.";?><BR> <?php } elseif(strtolower($_POST['pass']) != strtolower($_POST['cpass'])){ $errors = TRUE; echo "The Confirm password isn't equal to the password.";?><BR> <?php } else { $pass = strtolower($_POST['pass']); } if(!$_POST['email']){ $errors = TRUE; echo "You need to introduce an e-mail.";?><BR> <?php } elseif(strtolower($_POST['email']) != strtolower($_POST['cemail'])){ $errors = TRUE; echo "The Confirm e-mail isn't equal to the e-mail.";?><BR> <?php } else { $email = strtolower($_POST['email']); } if(strtolower($_POST['image_code']) != $_SESSION['image_code']){ $error = TRUE; $_SESSION['image_code'] = strtolower(substr(md5(time()), 0, 6)); echo "Invalid securety code.";?><BR> <?php } if($errors == FALSE){ include "config.php"; $bd_connection = mysql_connect(BD_SERVER, BD_ADMIN, BD_PASS) or die(mysql_error()); mysql_select_db(BD_LOGIN) or die(mysql_error()); $result = mysql_query("SELECT id FROM login WHERE nick = '$nick'") or die(mysql_error()); $num_rows_result = mysql_num_rows($result); if ($num_rows_result != 0) { echo "$nick is already in use.";?><BR> <?php } else { $result = mysql_query("SELECT id FROM login WHERE email = '$email'") or die(mysql_error()); $num_rows_result = mysql_num_rows($result); if($num_rows_result != 0) { echo "$email is already in use.";?><BR> <?php } else { $pass = md5($pass); $add_member = mysql_query("INSERT INTO login (nick, pass, email) VALUES ('$nick', '$pass', '$email')"); $code = md5(uniqid( time() . $_SERVER['REMOTE_ADDR'] . rand(0, 9) )); $result = mysql_query("SELECT id FROM login WHERE nick = '$nick'") or die(mysql_error()); $line = mysql_fetch_array($result); $id = $line['id']; mysql_query("INSERT INTO activation (id, code) VALUES ('$id', '$code')"); mysql_close($bd_connection); $email_mesage = '<p><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Bem-vindo ao SoccerPlayer!<p><p> Os seus dados são os seguintes:<p> Nickname: '.$nick.'<p> Password: '.$pass.'<p><strong> Código de activação: <a href="http://jarsantos.007ihost.com/activation.php?code='.$code.'">http://jarsantos.007ihost.com/activation.php?code='.$code.'</a></strong></p> <p> Tem uma semana para activar a sua conta.<p><p> Atenciosamente,<p> SoccerPlayer\'s Admins.'; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "From: \"João Santos\" <jarsantos@gmail.com>\r\n"; mail($email, "[soccerPlayer] Activação", $email_message, $headers); header("Location: login.php"); } } mysql_close($bd_connection); } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table border="0"> <tr><td>Username:</td><td> <input type="text" name="nick" maxlength="32"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr> <tr><td>Confirm Password:</td><td> <input type="password" name="cpass" maxlength="10"> </td></tr> <tr><td>E-mail:</td><td> <input type="text" name="email" maxlength="64"> </td></tr> <tr><td>Confirm E-mail:</td><td> <input type="text" name="cemail" maxlength="64"> </td></tr> <tr><th colspan=2><img src="img.php" /></th></tr> <tr><th colspan=2><input type="text" name="image_code" maxlength="6" /></th></tr> <tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table> </form> image.php <?php session_start(); if ($_SESSION['image_code']) { $code = $_SESSION['image_code']; header("Content-Type: image/png"); $width = 70; $heigth = 20; $image = imagecreate($width, $heigth) or die('Image create error!'); $bgcolor = imagecolorallocate($image, 255, 255, 255); $bordercolor = imagecolorallocate($image, 0, 0, 0); $linecolor = imagecolorallocate($image, 200, 110, 255); $fontcolor = imagecolorallocate($image, 0, 0, 0); // Criamos linhas na imagem for($x=7; $x < $width-7; $x+=5) { imageline($image, $x+7, 0, $x-7, $heigth-1, $linecolor); imageline($image, $x-7, 0, $x+7, $heigth-1, $linecolor); } // for for($y=3; $y < $heigth; $y+=3) imageline($image, 0, $y, $width-1, $y, $linecolor); // Escrevemos na imagem o conteúdo da variavel $cod imagestring($image, 5, 8, 1, $code, $fontcolor); imageline($image, 0, 0, 0, $heigth-1, $bordercolor); imageline($image, 0, 0, $width-1, 0, $bordercolor); imageline($image, 0, $heigth-1, $width-1, $heigth-1, $bordercolor); imageline($image, $width-1, 0, $width-1, $heigth-1, $bordercolor); imagepng($image); imagedestroy($image); } ?> Link to comment Share on other sites More sharing options...
NCS_One Posted November 28, 2007 at 11:30 AM Report Share #150864 Posted November 28, 2007 at 11:30 AM Ois A imagem nao deve tar a aparecer pq tu tens isto assim : <img src="img.php" /> Nao devia tar assim ? <img src="image.php" /> Quanto ao email nao sei. Se a vida te voltar as costas aproveita e apalpa-lhe o cu. Link to comment Share on other sites More sharing options...
Hipnoted Posted November 28, 2007 at 11:31 AM Report Share #150865 Posted November 28, 2007 at 11:31 AM Tens aqui um exemplo: http://www.portugal-a-programar.pt/index.php?showtopic=14103 "Nunca discutas com um idiota. Eles arrastam-te até ao seu nível e depois ganham-te em experiência" Link to comment Share on other sites More sharing options...
jarsantos Posted November 28, 2007 at 03:07 PM Author Report Share #150931 Posted November 28, 2007 at 03:07 PM Ois A imagem nao deve tar a aparecer pq tu tens isto assim : <img src="img.php" /> Nao devia tar assim ? <img src="image.php" /> Quanto ao email nao sei. tens toda a razão lol, que erro mais primário...era das horas e do cansaço.mas os mails nao sei, será que o host onde ando a testar tem isso bloqueado ou será que sou eu que estou a fazer mal? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now