• User Newbie

    Problema script attivazione registrazione

    Ciao a tutti.
    Aiuto!!!!!

    ho un problema con lo script di login e di attivazione.In pratica vorrei che nella pagina di attivazione(active.php) venisse visualizzato il numero di attivazione che viene creato in add.php..

    ADD.PHP

    [php]
    <?PHP
    //retrieve al the variables that had been submited by the from
    $username1 = $HTTP_POST_VARS["username"];
    $mailadres1 = $HTTP_POST_VARS["mailadres"];
    $password1 = $HTTP_POST_VARS["password"];
    $confirmpassword1 = $HTTP_POST_VARS["confirmpassword"];
    //generate an random number for the user neede to activate there account
    $actnum = rand( 1,999999999999);
    //make sure that the activation number is positive (YES it can happen that the number is negatief.)
    if ($actnum < 0){
    $actnum = $actnum + ($actnum*-2);
    }
    //set the error variable to an empty string.
    $error = "";
    //check it the fields are not empty. if they are, append the error to the error variable ($error)
    if ($username1 == ""){$error = "$error<li>No username given<BR>\n";}
    if ($password1 == ""){$error = "$error<li>No password given<BR>\n";}
    if ($mailadres1== ""){$error = "$error<li>No mailadres given<BR>\n";}
    //check if the passwords match. if they don't append the error to the error variable ($errir)
    if ($password1 <> $confirmpassword1) {$error = "$error<li>Passwords do not match<BR>\n";}
    // let the config.php file make an database connection
    include("config.php");
    //make an query which checks if the username OR the emailadres ar in the database. if they are append an error.
    $query = "Select * from signup where username='$username1' or mailadres='$mailadres1'";
    $result = mysql_query($query);
    if ($row = mysql_fetch_array($result)){
    if ($row["username"] == $username1){$error = "$error<li>Your username is already used by another member<br>\n";}
    if ($row["mailadres"] == $mailadres1){$error = "$error<li>Your e-mail adres is already registrated in our database<br>\n";}
    }
    //if ther error variable is still an empty string. The summission was oke and you can start proccesing the submission
    if ($error == ""){
    //first we check wat the date and time is for the signupdate field
    $datetime = date("d-m-Y G:i ");
    //then we submit al this to the database
    $query = "INSERT INTO signup (username, password, mailadres, actnum, userlevel, signupdate ,lastlogin, lastloginfail, numloginfail) VALUES ('$username1','$password1','$mailadres1','$actnum', '1', '$datetime','0','0','0')";
    $result = mysql_query($query);
    //and we make an (e-mail)message which contains the activation numer
    //also possible is to put a link in that message like :
    //http:-// your url /activate.php?username=$username1&actnum=$actnum
    //this would allow the user to direcly submit there activation without having to enter
    //al the data again in the activation form
    $message = "Activation number: $actnum";
    // mail the message to the user
    //mail($mailadres1, "Sign up script user activationcode", $message, "From: Sign-up script");
    // and redirect the user to the activation page
    header("Location: activate.php");
    }
    else
    //if $error is no longer a empty stirng there must have been error in the submision.
    //here we echo an nice line which says there are a coulple of errors and we onpen an
    //unorder list (just the <ul> tag) and we prinnt the error. also we include a link back to the
    //sign-upform
    {echo "You could not be added to the database because of the following reasons<ul>
    $error
    </ul>Please return to <a href="signup.php">signup form</a> and try again.";
    }
    ?>

    [/php]

    ACTIVE.PHP

    [php]
    <?PHP
    //retrieve the usernaem and the activation number from the url
    $username1 = $HTTP_GET_VARS["username"];
    $actnum1 = $HTTP_GET_VARS["actnum"];
    //let the config.php page connected to the database
    include("config.php");
    //check it the combination of username/password is correct.
    $query = "Select * from signup where username='$username1' And actnum='$actnum1'";
    $result = mysql_query($query);
    //if it is update the user's records. Set actnum to 0
    if ($row = mysql_fetch_array($result)){
    $query = "UPDATE signup Set actnum = '0' where username='$username1'";
    $result = mysql_query($query);
    // show the "thank you for activating" page.
    ?>
    <html>
    <head>
    <title>Activate account</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    Thank you for activating your account. You may now <a href="login.php">login</a>
    </body>
    </html>
    <?PHP }
    //if the username/actnum combination doesn't match check why.
    else
    {
    //if the username is empty just show the form.
    if ($username1 == ""){makeform();}
    //but if the username isn't empyt that means the user did submit the form.
    //therefore we print an error page and (again) the form.
    else
    {?>
    <html>
    <head>
    <title>Activate account</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form name="form1" method="get" action="activate.php">
    The username/activation-combination you entered is not correct. Please try again.<br>
    Username:
    <input name="username" type="text" id="username">
    <br>
    Activation code:
    <input name="actnum" type="text" id="actnum">
    <br>
    <input type="submit" name="Submit" value="Activate">
    </form>
    </body>
    <?PHP
    }
    }
    // the makeform function. prints the default form for activating.
    function makeform(){
    ?>
    <html>
    <head>
    <title>Activate account</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <form name="form1" method="get" action="activate.php">
    Thank you for signing up. An activationcode has been send to your e-mail adres.<br>
    Username:
    <input name="username" type="text" id="username">
    <br>
    Activation code:
    <input name="actnum" type="text" id="actnum">
    <br>
    <input type="submit" name="Submit" value="Activate">
    </form>
    </body>
    </html>
    <?PHP } ?>

    [/php]

    In teoria il numero di attivazione doveva essere mandato per mail ma vorrei che venisse visualizzato nella stessa pagina in cui devo inserirlo(active.php). Il codice scritto così funziona,ma voglio prelevare actnum dal db ma non ci riesco..

    Grazie a tutti


  • User Newbie

    Grazie a tutti ho risolto.....:fumato: