PDA

Orijinalini görmek için tıklayınız : Web hesabinin e-posta ile onaylanmasi islemi


tepisenordek
08-11-2007, 21:08 PM
SQL:

1.
2. /* tablo.sql */
3.
4. CREATE TABLE kullanicilar (
5.
6. eposta VARCHAR(255) NOT NULL,
7.
8. yaratilma_tarihi DATETIME NOT NULL,
9.
10. dogrulama_ifadesi VARCHAR(16) NOT NULL,
11.
12. onaylandi TINYINT UNSIGNED
13.
14. );


2.Asagidaki basit akis semasini kullanarak rastgele ifadeyi olusturup kullaniciya
e-posta ile gonderiniz: (Program anlatima yonelik oldugu icin butunsel
degildir.Veritabani icin bazi ek kodlamalar gerekebilir...)


gonder.php
PHP:

1.
2. <?php
3. // Rastgele bir karekter gurubu uretelim
4.
5. $dosgrulama_ifadesi = '';
6.
7. for ($i = 0; $i < 16; $i++) {
8.
9. $dogrulama_ifadesi .= chr(mt_rand(32,126));
10.
11. }
12.
13.
14. // Kullaniciyi ekle
15.
16. if (! mysql_query("INSERT INTO kullanicilar (eposta,yaratilma_tarihi,dogrulama_ifadesi,onaylan di)
17.
18.
19. VALUES ('".addslashes($eposta)."',NOW(),'".addslashes($dogrulama_ifadesi)."',0)")) {
20.
21. error_log("Bu kullaniciyi ekleyemiyorum: ".mysql_error());
22.
23. exit;
24.
25. }
26.
27.
28. $dogrulama_ifadesi = urlencode($dogrulama_ifadesi);
29.
30. $guvenli_eposta = urlencode($eposta);
31.
32.
33. $url = "http://www.turk-php.com/onayla.php";
34.
35.
36. $eposta_govdesi=<<<_EPOSTA_
37.
38. Merhaba $eposta:
39.
40.
41. Hesabinizi aktif hale getirmek icin asagidaki linke tiklayiniz:
42.
43.
44. $url?eposta=$guvenli_eposta&dogrulama_ifadesi=$dogrulama_ifadesi
45.
46.
47. Yedi gun icinde aktif hale getirilmeyen hesaplar sistemden silinir...
48.
49. _EPOSTA_;
50.
51.
52. mail($eposta,"Hesabin aktif hale gecirilmesi",$eposta_govdesi);
53. ?>



3.Simdi linkte tiklandiginda hesabi aktif hale gecirecek kodu yazalim:

onayla.php

PHP:

1.
2.
3. <?php
4.
5. $guvenli_eposta = addslashes($_REQUEST['eposta']);
6.
7. $guvenli_dogrulama_ifadesi = addslashes($_REQUEST['dogrulama_ifadesi']);
8.
9.
10. if ($r = mysql_query("UPDATE kullanicilar SET onaylandi = 1 WHERE eposta
11.
12. LIKE '$guvenli_eposta' AND
13.
14. dogrulama_ifadesi = '$guvenli_dogrulama_ifadesi' AND onaylandi = 0")) {
15.
16. if (mysql_affected_rows() == 1) {
17.
18. print "Tessekkurler hesabiniz onaylandi.";
19.
20. } else {
21.
22. print "Ozur dilerim,hesabinizin onaylanmasinda bir problem var.";
23.
24. }
25.
26. } else {
27.
28. print "Veritabani Hatasi:Lutfen daha sonra tekrar deneyiniz...";
29.
30. }
31. ?>


4.Verilen zaman dilimi icin, aktif hale gecirilmemis hesaplarin silinmesi:

sil.php
PHP:

1.
2. <?php
3.
4. $zaman_araligi = 7; // Yedi gun
5.
6.
7. if ($r = mysql_query("DELETE FROM kullanicilar WHERE onaylandi = 0 AND
8.
9. yaratilma_tarihi < DATE_SUB(NOW(),INTERVAL $zaman_araligi DAY)")) {
10.
11. if ($silinen_kullanicilar = mysql_affected_rows()) {
12.
13. print "Silinen kullanicilar $silinen_kullanicilar kullanici.n";
14.
15. }
16.
17. } else {
18.
19. print "Kullanici silinemiyor: ".mysql_error();
20.
21. }
22. ?>