There is a $variable
, its value is a big Array()
.
It is created inside the function one() { ... }
on the first.php
page.
first.php
has form with method="post"
, after submition page reloads on second.php
Is there any way to get value of $variable
inside function two() { ... }
on the second.php
?
Seems I can post value of $variable
within form, the problem is it can contain more than thousand symbols.
Thanks.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With