Zaman zaman kendi projelerimiz için test ortamları oluşturmamız gerekir. Bu test işlemlerinde verilerin birbirinden farklı olması sistemi daha rahat test etmemize yardımcı olur. Eğer bu tür işlemler için birbirinden farklı sahte e-posta adreslerine ihtiyaç duyuyorsak php ile rahatça oluşturabiliriz.
Aşağıdaki php fonksiyonunu kullanarak kendinize 1000 tane rastgele e-posta adresi oluşturup bunu veritabanınıza kaydedebilir veya link vermek için kullanabilirsiniz. Tamamen fonksiyonu kendi ihtiyacınıza göre özelleştirip, düzenlemenize bağlı bir durum.
Php Rastgele E-Posta Adresleri Oluşturma Fonksiyonu
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?php
// array of possible top-level domains
$tlds = array(“com”, “net”, “gov”, “org”, “edu”, “biz”, “info”);
// string of possible characters
$char = “0123456789abcdefghijklmnopqrstuvwxyz”;
// start output
echo “<p>\n”;
// main loop – this gives 1000 addresses
for ($j = 0; $j < 1000; $j++) {
// choose random lengths for the username ($ulen) and the domain ($dlen)
$ulen = mt_rand(5, 10);
$dlen = mt_rand(7, 17);
// reset the address
$a = “”;
// get $ulen random entries from the list of possible characters
// these make up the username (to the left of the @)
for ($i = 1; $i <= $ulen; $i++) {
$a .= substr($char, mt_rand(0, strlen($char)), 1);
}
// wouldn’t work so well without this
$a .= “@”;
// now get $dlen entries from the list of possible characters
// this is the domain name (to the right of the @, excluding the tld)
for ($i = 1; $i <= $dlen; $i++) {
$a .= substr($char, mt_rand(0, strlen($char)), 1);
}
// need a dot to separate the domain from the tld
$a .= “.”;
// finally, pick a random top-level domain and stick it on the end
$a .= $tlds[mt_rand(0, (sizeof($tlds)–1))];
// done – echo the address inside a link
echo “<a href=\”mailto:”. $a. “\”>”. $a. “</a><br>\n”;
}
// tidy up – finish the paragraph
echo “</p>\n”;
?>
|