There are a few ways to give a variable to anothe page, i think you don’t use any frameworks, so I’ll explain just the basic ways:
At first, start a Session. At the very first of your script, add this:
<?php
session_start();
?>
There must not be any other code before this, not even whitespace.
So now, you can set Session-Variables like this:
$_SESSION['cartTotal'] = $cartTotal;
The Variable $_SESSION[‘cartTotal’] will now be available on every page, you can use it just like a normal variable.
The second facility is, to give a variable to another page by it’s link with the GET-Method. E.G. set up your link like this:
<a href="https://stackoverflow.com/questions/9839926/site.php?cartTutorial=<?php echo $cartTutorial ?>">Link</a>
The Variable will be available in $_GET[‘cartTutorial’] but only in the next page and just by clicking this link. Also the GET-Method ist just good for simple variables, only text and numbers for example, arrays cannot be set.
Third possibility is the POST-Method, but it just works with a form and is just interesting if you are using one.
Simpliest possibility in my opinion is to make a session-variable.
3
solved php one variable on different pages [closed]