用md5哈希的php验证邮件并写入mysql

xv8emn3q  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(234)

我的网站上有这张表格。

<form id="contact-form" action="mail.php" method="POST">
                <input type="month" name="age" id="your-name" minlength="2" maxlength="2" placeholder="(your age here)" required><p>and</p>
                <input type="email" name="email" id="email" placeholder="(your email address)" required>
              <p>
                <button type="submit">
                  <svg version="1.1" class="send-icn" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="36px" viewBox="0 0 100 36" enable-background="new 0 0 100 36" xml:space="preserve">
                    <path d="M100,0L100,0 M23.8,7.1L100,0L40.9,36l-4.7-7.5L22,34.8l-4-11L0,30.5L16.4,8.7l5.4,15L23,7L23.8,7.1z M16.8,20.4l-1.5-4.3
                l-5.1,6.7L16.8,20.4z M34.4,25.4l-8.1-13.1L25,29.6L34.4,25.4z M35.2,13.2l8.1,13.1L70,9.9L35.2,13.2z" />
                  </svg>
                  <small>Subscribe</small>
                </button>
              </p>
              <span class="href"><p>By clicking subscribe button your agree to our <a href="term.html" target="_blank">Terms of Use</a></p></span>
            </form>

还有这个mail.php文件

<?php

    $url = 'url';
    $fromEmail = 'support@site.com';

    $Hash = md5(rand(0,1000)); //random hash for verification email

    // Grab our POSTed form values
    // Note that whatever is enclosed by $_POST[""] matches the form input elements
    $Age = $_POST["age"];
    $Email = $_POST["email"]; 
    // Connect to our DB with mysql_connect(<server>, <username>, <password>)
    $sql_connection = mysql_connect("host", "databasename", "password");

    mysql_select_db("database", $sql_connection);

    // Probably should check to make sure the connection was successful
    // But I'm too lazy...
 $query="select * from table where email = '$Email'";
    $result=mysql_query($query);
    $numOfRows=mysql_num_rows($result);
    if($numOfRows > 0)
    {
    echo 'email allready exist!';

    }
else
{   $sql = "INSERT INTO databasename (
                age,
                email,
                hash,
                date_1

            )
            VALUES (
                '". mysql_escape_string($age) ."', 
                '". mysql_escape_string($Email) ."',
                '". mysql_escape_string($Hash) ."',
                NOW()
            )";
    mysql_query($sql, $sql_connection);
    $to = $Email;
    $subject = 'Veryfi you sing up';
 $msg =   '

Thanks for signing up!
Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.

Please click this link to activate your account:
http://www.sait.com/verify.php?hash='.$Hash.'&email'.$Email.'

'; // Our message above including the link
    $headers = 'From:site.com' . "\r\n";

    mail($to, $subject, $msg, $headers);

    mysql_close($sql_connection);
    echo 'Check your email for a link ...';
}
?>

witch发送链接验证客户端电子邮件和写在数据库中的电子邮件散列年龄日期,但我有一个问题,当我点击链接验证,我不能想出它怎么为我做一切看起来像是正确的代码,但我是新的php和有许多要学的。这是我的第三个php文件verifye.php

$sql_connection = mysql_connect("host", "database", "pass");
mysql_select_db("databasename", $sql_connection);

$_GET['age'];
$_GET['email'];
$_GET['hash'];
$Active = 0;
//if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['hash']) && !empty($_GET['hash'])){
  if(isset($_GET['hash']) && !empty($_GET['hash']) AND isset($_GET['email']) && !empty($_GET['email'])){
    mysql_query("INSERT INTO seconddatabase (
                age,
                email,
                ip,
                hash,
                date_1

            )
            VALUES (
                '". mysql_escape_string($Age) ."', 
                '". mysql_escape_string($Email) ."', 
                '". mysql_escape_string($Ip) ."',
                '". mysql_escape_string($Hash) ."',
                NOW()
            )");
        echo 'you email was verefied';}
else{echo 'We have a problem at the moment please try again later'}

?>

如果有人能帮我,我会很高兴的。p、 我知道我的代码已经被弃用了,但现在我只想弄清楚如何让它这样工作。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题