I want to be able to use the same random number in two PHP files, but I see a different number.
[ransuu.php]
<?php
$random=ran(2,9);
?>
[file1.php]
<?php
include 'ransuu.php';
echo$random;//Example)2
?>
[file2.php]
<?php
include 'ransuu.php';
echo$random;//Example) 4
?>
I would like both of them to be the same number when I did echo, but I don't know how to do it, so could someone tell me?
Thank you for your cooperation.
Every time I access file1.php, file2.php, a new random number occurs, so
To use the same value for multiple PHP files, you basically use session variables.
in ransuu.php
<?php if(!isset($_SESSION['random'])$_SESSION['random']=land(2,9);?>
Then
file1.php, in file2.php
<?php if(isset($_SESSION['random'])) echo$_SESSION['random'];?>
Let's say
Hello,
As the questioner commented himself, I think we need to save the numbers somewhere and take them out.
Candidates include:
© 2023 OneMinuteCode. All rights reserved.