Problema con file di registrazione in php, non funziona e dà continui errori

PHPMan

Nuovo Utente
2 Feb 2015
17
2
0
PHP:
<?php


include("functions_custom.php");
include("register.php");
include("config.php");


$username = trim(stripslashes($_POST['username'])); // trim
$password = trim(stripslashes($_POST['password'])); // trim
$email = trim(stripslashes($_POST['email']));       // trim
$action = trim(stripslashes($_POST['action']));     // trim

if(isset($username) && isset($password) && isset($email)) {
      
      if(isset($action) && ($action=="Submit New Registration")) {

     $con = mysql_connect($host, $db_user, $db_psw);

                  mysql_select_db($db_name, $con);

$query = mysql_query("SELECT username FROM users WHERE username=".$username."");

if (! $query)

  {

      echo "<link href=\"css/custom_alert.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />
        <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>
        <script src=\"js/custom_alert.js\"></script>
        <script type=text/javascript>_alert('Error!','Username already exists! Choose another')</script>";
  }


  $sql = mysql_query("SELECT email FROM users WHERE email=".$email."");

if (! $sql)

  {
      echo "<link href=\"css/custom_alert.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />
        <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>
        <script src=\"js/custom_alert.js\"></script>
        <script type=text/javascript>_alert('Error!','Email already exists! Choose another')</script>";
  }
  

// Mail      
  
$to = $email;

$subject = "Confirm your registration";
$actioncode= generateRandomImpossibleTosolveString(10);
$activation_code= sha1(md5(sha1($actioncode)));
$urlencode_code = urlencode($activation_code);
$urlencode_username = urlencode($username);

$body = "

Hi ".$username.",

This is a email for confirming your registration at ".$website."

Please, for done it, go to following link:

http://".$website."/regverify.php?activationcode=".$urlencode_code."&username=".$urlencode_username."

You will must insert following credentials:

Username = ".$username.";
Confirm Code = ".$activation_code.";

Enjoy in our community!
 
";

$headers = "From: Confirm Your Registration!<regmodule@".$website.".it>";


if(@mail($to, $subject, $body, $headers)) { 

  echo "<link href=\"css/custom_alert.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />
        <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>
        <script src=\"js/custom_alert.js\"></script>
        <script type=text/javascript>_alert('Success!','An email will be sended to your email address, check and follow instructions in it', 'index.php')</script>";

} else {

  echo "<link href=\"css/custom_alert.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />
        <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>
        <script src=\"js/custom_alert.js\"></script>
        <script type=text/javascript>_alert('Error!','Impossible sending email to your email address!', 'register.php')</script>";

}

    if(isset($_GET['username']) && isset($_GET['activationcode']) && ($_GET['username'] == $username) && ($_GET['activationcode']) == $activation_code) {


$value = "true";
$urlencode_value = urlencode($value);

                
                echo "<html>
<head>
 
    <title>Confirm Module</title>
 
    <link href=\"css/access.css\" rel=\"stylesheet\" type=\"text/css\" />
</head>
<body>
 
    <form id=\"login\" action=\"regverify.php?activationcode=".$urlencode_code."&username=".$urlencode_username."&confirm=".$urlencode_value."\" method=\"post\">
        <fieldset id=\"inputs\">
            <input id=\"username\" name=\"usernameact\" type=\"text\" placeholder=\"Username\" autofocus required>
            <input id=\"password\" name=\"actcode\" type=\"password\" placeholder=\"Activation Code\" autofocus required>
        </fieldset>
        <fieldset id=\"actions\">
            <input type=\"submit\" id=\"submit\" name=\"action\" value=\"Send your confirm\">
        </fieldset>
    </form>
 </body>
</html>";


if(isset($_GET['confirm']) && ($_GET['confirm'] == $value) && isset($_GET['activationcode']) && ($_GET['activationcode'] == $activation_code)
&& isset($_GET['username']) && ($_GET['username'] == $username) && isset($_POST['unsernameact']) && ($_POST['usernameact'] == $username)
&& isset($_POST['actcode']) && ($_POST['actcode'] == $activation_code) && isset($_POST['action']) && ($_POST['action'] == "Send your confirm"))

{

$now = TIME_NOW;

          
                    
     $sql = mysql_query("ALTER TABLE users ADD activationcode varchar(120) AFTER email");
     $querysql = mysql_query("ALTER TABLE users ADD lastvisit int unsigned AFTER activationcode");
     $querymysql = mysql_query("ALTER TABLE users ADD lastactive int unsigned AFTER lastvisit");
     $sqlquery = mysql_query("ALTER TABLE users ADD memregdate int unsigned AFTER lastactive");

include("functions_custom.php");

           $salt= generateRandomImpossibleTosolveString(100);
           $saltedpsw= sha1(md5($salt.sha1($password)));
           $now = TIME_NOW;

     $query = mysql_query("INSERT INTO users (username, password, email, activationcode, lastvisit, lastactive, memregdate) VALUES ($username, $password, $email, $activation_code, $now, $now, $now)");

     while($done = mysql_fetch_array($query)) {

            
             $user = array(

             "username" => $username,
             "password" => $saltedpsw,
             "email"    => $mail,
             "activationcode" => $activation_code,
             "lastvisit" =>  $now,
             "lastactive" => $now,
             "memregdate" => $now

            );


       echo "<link href=\"css/custom_alert.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />
        <script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"></script>
        <script src=\"js/custom_alert.js\"></script>
        <script type=text/javascript>_alert('Success!','Congratulations! You have confirm successfully your reg request, now you can connect to forum!', 'index.php')</script>";


     }


}

    }


      }

}

?>
C'è un problema con il file regverify.php Ciò che vorrei fare è registrarsi, controllare se l'username o l'email immessa già esiste, se esiste faccio apparire un alert personalizzato. Senno invio la mail con il codice di conferma e faccio apparire un html per confermare la registrazione cliccando sul link, se sarà confermato sarà inserito tutto nel database, ma non funziona un cazzo.

http://hydrerscript.altervista.org/register.php <--- Provare per credere


Aiutatemi!