如何在2个不同的php页面中包含相同的随机结果?

如何在2个不同的php页面中包含相同的随机结果?

问题描述:

main.php => include("". rand(1,3) .".php");    

I need to include same result in main.php in a second page main_final.php.

How can i do for main_final to include same result that main.php?

thank you very much !

You may use variables to do that. Store you result in the proper predefined variable: http://php.net/manual/en/reserved.variables.php

And read the value from both files. For example in main.php:

$_SESSION["randomvalue"] = rand(1,3);

In the second file:

include($_SESSION["randomvalue"] .".php");

$_SESSION['page'] = rand(1,3) .".php";
include( $_SESSION['page'] ); 

so you can use the same variable in both pages. it can handle many users depending on your server. this is the best and the simplest way.