<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" 
            content="text/html;charset=utf-8" />
        <title>Registrierung erfolgt...</title>
        <link rel="stylesheet" type="text/css" href="Styles/style.css" />
    </head>
    
    <body>
        <?php
            mysql_connect("localhost", "root", "R2d2C3pO") or die (mysql_error());
                // Datenbank auswählen
                mysql_select_db("Benutzer") or die(mysql_error());
                    $_username = mysql_real_escape_string($_POST['username']);
                    $_passwort = mysql_real_escape_string($_POST["passwort"]);
                    $_email = mysql_real_escape_string(strtolower($_POST["email"]));
                    
                    $_sql = "SELECT * FROM benutzer WHERE benutzername='$_username'";
                    
                    $_res = mysql_query($_sql);
                    $_anzahl = @mysql_num_rows($_res);
                    
                    $_sql_email = "SELECT * FROM benutzer WHERE email='$_email'";
                    
                    $_res_email = mysql_query($_sql_email);
                    $_anzahl_email = @mysql_num_rows($_res_email);
                    $row = mysql_fetch_object($_res);
                    $_id_und_passwort=$_email||$_passwort;
                    $_token=md5($_id_und_passwort);
                    
                    if (!isset($_POST["Submit"])) {
                        if (!empty($_passwort) and !empty($_username) and $_anzahl == 0 and check_email_mx($_email) and $_POST['passwort'] == $_POST['repeatedpasswort'] and empty($_anzahl_email) and isset($_POST["AGB"])){
                            echo "<p>Registrirung Erfolgreich :)</p>";
                            $strSQL = "INSERT INTO benutzer(benutzername, passwort, email, token) VALUES('".$_POST['username']."',  '".$_POST['passwort']."',   '".$_POST['email']."', '".$_token."')";
                            mysql_query($strSQL) or die (mysql_error());
                            $_aktLink= '<a href="AccAktivierung.php?token='.$_token.'">Klicken sie hier um ihren Acc zu aktivieren!</a>';  
                            mail($_email,"Acc aktivierung :)","
                                <B>Hallo :)</B><BR>
                                Bitte klicken sie den unten stehenden Link um ihren Account zu aktivieren.<br />
                                ".$_aktLink."<br /> 
                                Bitte anworten sie nicht auf diese Email, denn sie ist automatisch geniert. Iher PW-Games Service-Team ;)",
                                "From: PW-Games Aktivierungs-Service <[email protected]>
                                Content-Type: text/html");
                            header("Location: http://localhost/");
                            mysql_close();
                            exit();
                        }
                        if ($_anzahl > 0){
                            echo "<p>Benutzername bereits vorhanden!</p>";
                            include("Registrationsformular.html");
                            mysql_close();
                            exit();
                        }
                        if (!check_email_mx($_email)){
                            echo "<p>Keine gültige E-mail Adresse!</p>";
                            include("Registrationsformular.html");
                            mysql_close();
                            exit();
                        }
                        if ($_POST['passwort'] != $_POST['repeatedpasswort']){
                            echo "<p>Passwörter stimmen nicht über ein!</p>";
                            include("Registrationsformular.html");
                            mysql_close();
                            exit();
                        }
                        if ($_anzahl_email > 0){
                            echo "<p>Email bereits vorhanden!</p>";
                            include("Registrationsformular.html");
                            mysql_close();
                            exit();
                        }
                        if (empty($_username)){
                            echo "<p>Bitte geben sie einen Benutzernamen ein!</p>";
                            include("Registrationsformular.html");
                            mysql_close();
                            exit();
                        }
                        if (empty($_passwort)){
                            echo "<p>Bitte geben sie ein Passwort ein!</p>";
                            include("Registrationsformular.html");
                            mysql_close();
                            exit();
                        }
                        if (!isset($_POST["AGB"])){
                            echo "<p>Sie müssen die AGB aktzeptieren!</p>";
                            include("Registrationsformular.html");
                            mysql_close();
                            exit();
                        }
                    }
                // Schließt die Datenbankverbindung
            mysql_close();
        
        ?>
            <div id="text">Dieser Text wird vor Ablauf des ersten Countdowns angezeigt.</div><div id="zeit"></div>
            <script type='text/javascript'>
                Countdown(10);
                
                function Countdown(Zeit) {
                    Zeit--;
                    return Zeit
                }
            </script>
    </body>
    
</html>
<?php
function check_email_mx($email) {
    if(
        (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) || 
        (preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) 
    ) {
        $host = substr($email, (strpos($email, '@')+1));
        if(checkdnsrr($host.'.', 'MX') ) return true;
        if(checkdnsrr($host.'.', 'A') ) return true;
        if(checkdnsrr($host.'.', 'CNAME') ) return true;
    }
    return false;
} 
?>