Creating a random number that will be used as the same thing on subsequent pages

I am currently creating a random number for my ad landing page to use MB , and it works beautifully.

But I am wondering if it is possible for me to somehow get the same number that is created each time with <?php echo(rand(10,20)); ?> <?php echo(rand(10,20)); ?> , so I can use it in several places.

+5
source share
1 answer

This can be done using sessions.

First you need to start a session, assign a session array to a random function, then a variable from that session array.

 <?php session_start(); $_SESSION['var'] = rand(10,20); $var = $_SESSION['var']; 

You can then use this on subsequent pages, while you also start a session on these pages.

Link:

Example:

File 1

 <?php session_start(); $_SESSION['var'] = rand(10,20); echo $var = $_SESSION['var']; 

File 2

 <?php session_start(); echo $var = $_SESSION['var']; 

Sidenote:

Make sure there is nothing higher than this, as this may cause notification of sent headers.

If you received it, go to the next page on Stack:

+3
source

Source: https://habr.com/ru/post/1238551/


All Articles