|
|
|
การสร้าง random password ไม่ให้ซ้ำกัน ในระบบ Register แบบ batch file คือสร้างหลายๆ user ในครั้งเดียว |
|
|
|
|
|
|
|
คือทำให้รับค่าทีละหลายๆคนได้แล้วคับ แต่รหัสที่ได้เป็นรหัสเดียวกันหมดเลยคับ
ขอคำแนะนำด้วยนะคับ
ขอบคุณมากคับ
Code (PHP)
<?
$conn = mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("csv",$conn);
if(isset($_POST['submit']))
{
$file = $_FILES['file']['tmp_name'];//
//echo $file;
$handle = fopen($file,"r");
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
//echo randomPassword();
$pw = randomPassword(10);
while (($fileop = fgetcsv($handle,1000, ",")) !== false)
{
$firstname = $fileop[0];
$lastname = $fileop[1];
$email = $fileop[2];
$sql = mysql_query("INSERT INTO test (first_name,last_name,email,Password)
VALUES ('$firstname','$lastname','$email','$pw')");
if($sql)
{
echo 'successfully';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="mainWrapper">
<form method="post" action="test1.php" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" name="submit" value="Submit"/>
</form>
</div> <!--end mainWrapper-->
</body>
</html>
Tag : PHP, MySQL, CakePHP
|
|
|
|
|
|
Date :
2013-05-30 21:05:44 |
By :
mrronalz |
View :
1338 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ดูดีๆ
$pw = randomPassword(10);
มันอยู่นอกลูป while ครับ
มันจึงเป็นค่าเดียวตลอดไงล่ะครับ
|
|
|
|
|
Date :
2013-05-30 21:08:53 |
By :
cookiephp |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โอ้ จริงๆด้วยคับ T^T
ขอบคุณมากๆนะคับผม .
|
|
|
|
|
Date :
2013-05-30 21:33:35 |
By :
mrronalz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|