Use "session_start()
" function at the very beginning of any PHP web page, just after the first PHP start tag (<?php
).
Then store the variable of yours into a superglobal session array variable, in the "first.php" page like:-
<?php
session_start(); // This line must be at the very beginning of this PHP page.
function one() {
// blah, blah, ...
if(isset($variable) && !empty($variable)) {
$_SESSION['customVariable'] = $variable;
}
// some more blah, blah, ...
}
?>
Now if you come to the "second.php" page, you need to access this page's function as:-
<?php
function two() {
// if any blah, blah, ...
if(isset($_SESSION['customVariable']) && !empty($_SESSION['customVariable'])) {
$variable = $_SESSION['customVariable'];
}
// next series of blah, blah, ...
}
?>
But in this "second.php" page, the "session_start()
" function must be written at the very beginning of this page just after the first PHP start tag.
Hope it helps.