Acknowledgement{Confirmation} of registration on RNR

Greetings to all who at present to be in this imagined audience, and will listen to now intolerable delirium of old professor J


Well, if have started so the subject of today's lecture will be those - " Acknowledgement{Confirmation} of registration on RNR ".


Yes, it now rather popular mechanism and though sometimes he seems unimaginably complex , he is so simple as your first calculator on RNR. Concerning to technical requirements from your server for an embodiment of all that we shall do{make} now so it is required to you much, itself RNR, it is desirable not below 4.39 and certainly established SUBD (in this lecture I shall be based on MySQL-comprehensible SQL a code).


So, the small lyrical introduction have passed, now let's plunge into the world of programming and these chjortovykh algorithms. For the beginning we will need to write function for registration of the user on your site. The ambassador it will be necessary to send letters to the user, with the notice on registration and the prevention{warning} that if was registered that be kind, to proceed{pass} on links and to confirm it, so, for confidence, that you not "khacker". Well, and third our step will be to check of that activation. And the fourth step as you have already guessed (in fact so?), it will be sonorous J. So, let's more in detail talk about registration. This part rather not complex  and if you know how her  to do{make}, I do not advise to read further, and at once to pass to the second step.


Let's say goodbye to everyone who has gone on practice, let the ground him  will be down J, well and we with you shall take the first step now in functional base of the project.


But all over again let's place all points above "¿". To be necessary for us for registration the tablet in a DB with a name, say, "users". There there should be following fields: id, login, passwd, email, status. It is the minimal set of fields, and at desire can add them. In a field of the password, we shall write down not simply text value of the password, and his  ciphered variant (MD5).


Well, it seems to me, that on it it is possible to finish this verbalization and to proceed{pass} to a practical part:



<?


// The interface of the user


echo "<html>";


echo "<head>";


echo " <title> ShockStudio RegistrationModule </title> ";


echo " <meta http-equiv = "Content-Type" Content = " text/html;

charset=windows-1251 ">";


echo " <meta name = "Author" Content = " LoRd aka K.Karpenko "> ";


echo " <meta name = "owner" Content = " ShockStudio Team "> ";


echo "</head>";


echo " <body onLoad = " alert (' All rights reserved! ') "> ";


echo " <form action = "" method = "post" name = "reg"> ";


echo " <table style = " width:400px; height:50px; border:1px; "

     align = "center"> ";


echo " <tr> <td colspan = "2" style = "text-align:center">

     The registration form </td> </tr> ";


echo " <tr> <td> your login: </td> <td> <input

     type = "text" name = "login"> </td> </tr> ";


echo " <tr> <td> your password: </td> <td> <input

     type = "password" name = "passwd"> </td> </tr> ";


echo " <tr> <td> yours email: </td> <td> <input

     type = "email" name = "email"> </td> </tr> ";


echo " <tr> <td> yours IP: </td> <td> ". $ _SERVER ['REMOTE_ADDR'].

    " </td> </tr> ";


echo " <tr> <Td colspan = "2"> <input type = "submit" name = "reg"

     value = "Further"> </td> </tr> ";


echo "</table>";


echo "</form>";


// If the button has been pressed that is checked the data


if (isset ($ _POST ['reg'])) {

    $login = $ _ POST ['login'];

    $passwd = $ _ POST ['passwd'];

    $email = $ _ POST ['email'];

    $ip = $ _ SERVER ['REMOTE_ADDR'];

    if (trim ($login) == ") {

    die (" you have not entered a login! ");

}


if (trim ($passwd) == ") {

    die (" you have not entered the password! ");

}


if (trim ($email) == ") {

    die (" you have not entered yours EMAIL! ");

}


// We check validnost` the electronic address of the user


if (! preg_match (" / ^ [a-zA-Z0-9_-.] + (?: [a-zA-Z0-9 _] {1,3})

    +. [a-zA-Z0-9 _] {1,3}) + (. [a-zA-Z0-9 _] {1,3}) * / ", $ email)) {

    die (" the Erroneous format of the EMAIL-address! ");

}


// The password should not be less than 3 symbols

if (strlen ($passwd) <3) {

    die (" the Length of the password should be not less than 3 symbols! ");

}


// We cipher the password

$passwd=md5 ($passwd);


// Connection with a DB

$conn_id = mysql_connect ("localhost", "root", " ") or die (" the Mistake at connection to a DB! ");

@mysql_select_db ($conn_id);


// And the user is not registered yet?


$q = mysql_query (" SELECT id FROM 'users' WHERE login = ' ". $ login. " ' OR

   email = ' ". $ email. "'", $ conn_id);


if (@mysql_error ($conn_id)! = ") {

    die (" the Mistake in search to a DB! ");

}


if (@mysql_num_rows ($q)! =0) {

    die (" the Given user is already registered! ");

}

else {

    unset ($q);

    // We register the user

    $q = mysql_query (" INSERT into 'users' VALUES (", ' ". $ login. " ',' ". $ passwd.

                    " ', ' ". $email. " ' ', ". $ ip. " ','off ') ", $conn_id);


    if (@mysql_error ($conn_id)! = ") {

        die (" the Mistake in search to a DB! ");

}

}


/ **


*Nachinaem process of drawing up of the KHESH-SIGNATURE, for acknowledgement{confirmation} of the person

*pol`zovatelja at activation


**/


// We receive a login of the user in a EMAIL-network


$email_cnx=explode (, $email);


// We form the signature

$checkSum=base64_encode (substr ($login, 0,3). $email_cnx [0].

          md5 ($ _SERVER [' REMOTE_ADDR ']));


// We receive a time label


$date=time ();

unset ($q);


// We add the data in the time table


$q = mysql_query (" INSERT into 'validate_temp' VALUES (", ' ". $ email. " ',' ".

                 $checkSum. " '', ". $ date. " ') ", $ conn_id);


if (@mysql_error ($conn_id)! = ") {

    die (" the Mistake in search to a DB! ");

}


// The message to the registered user


$message = " Today in " .date (" d.m. Y ", $date). " On a site ShockStudio.COM was

It is registered

The user with yours email'om. Therefore you have received the given letter. If you not

Were registered on our site simply remove the given letter and if

It were you that pass under the mentioned below link.


The account will be valid up to

" .date (" d.m. Y ", mktime (0,0,0, date ("d", $date) +4, date ("m", $date), date ("Y", $date))). ",

Then an account to register it will be impossible!


The link for activation: <a

href = " activate.php? checkSum = ". $ checkSum. " and email = ". $ email. ""> To proceed{pass} </a>;


-----------------------------


Yours faithfully administration ShockStudio.COM

Email for contacts: <a href = " mailto: Ik1990@list.ru "> Ik1990@list.ru </a> ";


// We send the message to the user


@mail ($email, " Activation of an account ", $message, " Content-Type: text/html;

charset=windows-1251 "," From: robot@shockstudio.com ");


@mysql_close ();


?>


As you can see, especially complex  here there is nothing, well except for time labels. We form all these labels with the purpose of check of time of activation. In fact if the user is purposefully registered, he will not wait days and nights, for activation of the bill.


Well, now my dear students, we shall pass to the main stage of our lecture, namely check and according to activation of an account.


As you have already understood, you need to create a separate script, which will check validnost` the data transferred{handed} under the link which will be received by the user, the Principle of check in generating the new signature according to those to the data which are received from the user and through the link on which he has come. The ambassador if the data are correct, we activate an account of the user and we speak "Find fault", differently we speak "Baj" J.


Let's see, as it looks:



<?


$checkSum = $ _ GET [' checkSum '];


$email = $ _ GET [' email '];


$ip = $ _ SERVER [' REMOTE_ADDR '];


$conn_id = mysql_connect ("localhost", "root", " ") or die (" the Mistake at connection to a DB! ");

@mysql_select_db ($conn_id);

$q = mysql_query (" SELECT id FROM 'validate_temp' WHERE email = ' ". $ email. "'", $ conn_id);


if (@mysql_error ($conn_id)! = ") {

    die (" the Mistake in search to a DB! ");

}


if (@mysql_num_rows ($q) == 0) {

    die (" the Mistake at check of the data! ");

}


$q = mysql_query (" SELECT login, date FROM 'users' WHERE email = ' ". $ email. "'");


$row = mysql_fetch_array ($q);


$login = $ row [' login '];

$date = $ row [' date '];


$time=time ();


$total_date = $ time-$ date;


$date = $ time + $ total_date;


$end_time=date ("d:m", $time);


$date_stamp=explode (":", $end_time);


if ($date_stamp [1]! =date ("m", $date) || ($date_stamp [0]-date ("m", $date))> 4) {

    die (" Prosrochenaja activation of an account! ");

}


$email_cnx=explode (, $email);

$new_checkSum=base64_encode (substr ($login, 0,3). $email_cnx [0] .md5 ($ _SERVER [' REMOTE_ADDR ']));


if ($checkSum! = $new_checkSum) {

    die (" the Mistake at check of a key! ");

}

else {

    unset ($q);

    $q = mysql_query (" UPDATE ` users ` SET status ='on ' WHERE email = ' ". $ email. "'", $ conn_id);

    if (@mysql_error ($conn_id)! = ") {

        die (" the Mistake in search to a DB! ");

}

}


$q = mysql_query (" DELETE FROM 'validate_temp' WHERE email = ' ". $ email. "'", $conn_id);


if (@mysql_error ($conn_id)! = ") {

    die (" the Mistake in search to a DB! ");

}


@mysql_close ($conn_id);


?>


That's all. As you can see, anything complex  here no. First we check, whether there is an account with similar EMAIL at the table for activation and if there is no that mersi to a side. The ambassador we get value of a login and date of registration from the table. Then we check, whether activation is delayed, notice in rather original way. That is all over again we receive date of registration, and date current. After that we receive a difference of the current time label, and a time label during registration then we add a difference of time labels to a time label during registration (J), well and in consequence{investigation} we receive value of day and month from a resulting time label (it is direct a rapid speech any J), and already only after that inspect dates. She consists in checking up, whether months are equal during registration or the ambassador, well that is if no she precisely unsuitable to activation if they are equal that we check value of a difference of days and if the difference is more 4 we stop job.


See, I spoke, all is extremely easy J


Well, sirs students. Who has reached, and who has fallen death brave, during studying given clause{article}, anyway our lecture comes to an end. As the conclusion I want to say, that to perfection of a limit no, and I hope, that of all this brothel{disorder} into which I have transformed a script you can easy make that corresponds{meets} to your mentality, and to customs. Such style of a spelling is inherent in me personally if he confuses you and you do not understand (and I hope it not so) what that there were his  parts from the very beginning try to reconstruct those functions which confuse you under understandable to itself of manners, will see, the script becomes much easier, in fact as speak in people the shirt always closer.