开发者

Rand() returns same value; in a hidden input

开发者 https://www.devze.com 2023-04-13 03:05 出处:网络
For some reason if I try to assign a value to my input type hidden then I always get the same value (1), I can assign a value to it with javascript but not php..:

For some reason if I try to assign a value to my input type hidden then I always get the same value (1), I can assign a value to it with javascript but not php..:

<?php
 $num = rand(1, 4);                     
?>  

 <?php echo $num; ?><?php echo $num; ?><?php echo $num; ?>

<input type="hidden" value="<?php echo $num; ?>" name="catch_num1">

If rand gave 4 this would give 444 but in input type it would always give value="1"??

It seems li开发者_JAVA技巧ke a bug to me but I'm checking all my code in between.


Might be you set constant value to http://cz2.php.net/srand in prior to calling rand.


It can't be. rand(min, max) always gives value between the min and the max.

Have you tried rand(4, 14)? does it give you 1 too? are you sure you echo the $_POST value that actually IS this one and not another?

Try using mt_rand()

Edit: well, I have found lots of results of the same problem. But each got its own reason.

If you're using Firefox for example, refresh using CTRL+F5 to omit cache. The random number might have been stored in cache or something?!

0

精彩评论

暂无评论...
验证码 换一张
取 消