n_a602
یک شنبه 10 مهر 1390, 10:18 صبح
توی کدی که واسه شما فرستادم یک عدد پنج رقمی با ارقم بدون تکرار (مثلا 12345 یا 87659)تولید میشه که توی ارایهrandبه طوری که هررقم توی یک خونه ارایه randاست بازدن دکمه start ریخته میشه(البته چون بایدعدد ارقام بدون تکرار داشته باشه گاهی باید چند بار دکمه startکلیک کرد)بعد حالا کاربرباید این عدد پنج دقمی رو حدس بزنه هررقمش رو توی یک nputینویسه بعد دکمهlevel و که فشار داد هرعددش با عدد تصادفی مقایسه میشه برای ارقامی که دقیقا یکان اونها برابر عدد تصادفی بود رنگ فونت inputمربوط به اون رقم مثلا سبز میشه ولی اگررقمی که وارد کرده درعدد تصادفی بود ولی یکانش متفاوت بود رنگش قرمزبشه
مثلا عدد تصادفی 78954
عدد حدسی کاربر 91046
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd (http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)">
<html xmlns="http://www.w3.org/1999/xhtml (http://www.w3.org/1999/xhtml)">
<head><link rel="stylesheet" type="text/css" href="style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.error1
{
background-color:red;
color:white;
}
.error2
{
background-color:#039;
color:white;
}
</style></head>
<body>
<form id="form1" name="form1" method="get" action="">
<p> </p>
<p>
<input type="submit" name="start" id="button" value="Start" />
<p>
<label>:
<input type="text" name="0" id="0" value="<?php if (isset($_GET['0'])) echo $_GET['0']; ?>" class="<?php
if(isset($_GET['level']))
{
$temp[0]=$_GET[0];
$n=$_SESSION['rand'][0];
for($j=1;$j<=5;$j++)
{
if($n==$temp[$j-1])
{
if(0==$j-1)
{
echo'error1';
}
else
{
echo'error2';
}
}
}}
?>" />
</label>
<label>
<input type="text" name="2" id="2" value="<?php if (isset($_GET['2'])) echo $_GET['2']; ?>"/>
</label>
<label>
<input type="text" name="3" id="3" value="<?php if (isset($_GET['3'])) echo $_GET['3']; ?>"/>
</label>
<label>
<input type="text" name="4" id="4" />
</label>
<label>
<input type="text" name="5" id="5" value="<?php if (isset($_GET['5'])) echo $_GET['5']; ?>"/>
<br />
nokteh:dar har input faghat yek ragham vard konid<br />
<br />
</label>
<input type="submit" name="level" id="button2" value="level1" /> </form>
<?php
session_start();
// ...هرباریک عدد پنج رقمی به صورت رندوم انتخاب میشودایجاد یک عدد تصادفی پنج رقمی و قراردادن ان در ارایه نکته ارقام این عدد پنج رقمی غیرتکراری است
if(isset($_GET['start']))
{
$_SESSION['rand'] = array();
$rand = rand(9999,99999);
$f =wordwrap($rand, 1, '-',true);
$g=explode('-',$f);
for ($i=0;$i<=5;$i++)
{
$num=$g[$i];
for($j=$i+1;$j<=5;$j++)
{
if($num==$g[$j])
exit;
else
$_SESSION['rand'][$i]=$g[$i];
}
}
print_r ($_SESSION['rand']);
}
echo $rand;
?>
</body>
</html>
مثلا عدد تصادفی 78954
عدد حدسی کاربر 91046
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd (http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd)">
<html xmlns="http://www.w3.org/1999/xhtml (http://www.w3.org/1999/xhtml)">
<head><link rel="stylesheet" type="text/css" href="style.css"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.error1
{
background-color:red;
color:white;
}
.error2
{
background-color:#039;
color:white;
}
</style></head>
<body>
<form id="form1" name="form1" method="get" action="">
<p> </p>
<p>
<input type="submit" name="start" id="button" value="Start" />
<p>
<label>:
<input type="text" name="0" id="0" value="<?php if (isset($_GET['0'])) echo $_GET['0']; ?>" class="<?php
if(isset($_GET['level']))
{
$temp[0]=$_GET[0];
$n=$_SESSION['rand'][0];
for($j=1;$j<=5;$j++)
{
if($n==$temp[$j-1])
{
if(0==$j-1)
{
echo'error1';
}
else
{
echo'error2';
}
}
}}
?>" />
</label>
<label>
<input type="text" name="2" id="2" value="<?php if (isset($_GET['2'])) echo $_GET['2']; ?>"/>
</label>
<label>
<input type="text" name="3" id="3" value="<?php if (isset($_GET['3'])) echo $_GET['3']; ?>"/>
</label>
<label>
<input type="text" name="4" id="4" />
</label>
<label>
<input type="text" name="5" id="5" value="<?php if (isset($_GET['5'])) echo $_GET['5']; ?>"/>
<br />
nokteh:dar har input faghat yek ragham vard konid<br />
<br />
</label>
<input type="submit" name="level" id="button2" value="level1" /> </form>
<?php
session_start();
// ...هرباریک عدد پنج رقمی به صورت رندوم انتخاب میشودایجاد یک عدد تصادفی پنج رقمی و قراردادن ان در ارایه نکته ارقام این عدد پنج رقمی غیرتکراری است
if(isset($_GET['start']))
{
$_SESSION['rand'] = array();
$rand = rand(9999,99999);
$f =wordwrap($rand, 1, '-',true);
$g=explode('-',$f);
for ($i=0;$i<=5;$i++)
{
$num=$g[$i];
for($j=$i+1;$j<=5;$j++)
{
if($num==$g[$j])
exit;
else
$_SESSION['rand'][$i]=$g[$i];
}
}
print_r ($_SESSION['rand']);
}
echo $rand;
?>
</body>
</html>