How to pass variable to next page with PHP?

Spread the love

Sometimes, we want to pass variable to next page with PHP.

In this article, we’ll look at how to pass variable to next page with PHP.

How to pass variable to next page with PHP?

To pass variable to next page with PHP, we can use a session or cookie.

For instance, we write

$_SESSION['varname'] = $var_value;

to store $var_value in a $_SESSSION array entry in the source page.

Then we get the value in the destination page with

$var_value = $_SESSION['varname'];

Likewise, we can replace SESSION with COOKIE.

For instance, we write

$_COOKIE['varname'] = $var_value;

to the source page to store $var_value in a cookie entry.

And then in the destination page, we write

$var_value = $_COOKIE['varname'];

to get the value.

Conclusion

To pass variable to next page with PHP, we can use a session or cookie.

Leave a Reply

Your email address will not be published. Required fields are marked *