You don't use PHP to pass values from page to page. Typically, you'd use HTML forms to pass values. You have many choices for passing variables between pages with HTML: GET, POST, or COOKIE. (Optionally, you can use a session variable.)
- Cookie is the most complicated and insecure, so let's skip that one for now.
GET and POST are similar methods but GET appears in the URL, so I usually stick with POST.
Example1: POST
<form name="myform" action="page2.php" method="post">
<input type="hidden" name="var1" value="10">
<input type="text" name="var2" value="4">
<input type="button" name="var3" value="7">
<input type="text" name="var4" value="Hello World">
<input type="submit" name="submit" value="Submit to Page 2">
</form>
I used a bunch of input types here just for illustration. Be aware of the behavior of each type of input (i.e. - unless the check box is checked, it does not submit a value to Page 2). I'll let you look that up.
Generally, if you don't want the user to tinker with your value, you will use "hidden" types which always get submitted to the next page. Also be aware that you can submit to the same page - depending on what you're trying to accomplish. For example, if you're just sorting some values differently, you won't want to build a whole new page.
The way you access values on the target page is through the php $_POST array. If you want to see if a value was posted, you can use a statement like:
if(isset($_POST['var1'])) echo "Yep, var1 is set!";
I prefer simply to extract all the POST values into local variables (with the same name as the HTML input fields from Page1) so I can work with them more easily.
Page 2:
extract($_POST);
if(isset($var1)) echo "Yep, var1 is set!";
The only time I think GET makes sense is when you want to use a link instead of a form. Then you can control the GET values manually:
<a href="page2.php?var1=10">Send $_GET['var1'] to Page 2</a>
If you use GET this way, be careful what you use var1 for. If you use var1 in a database query, for example, a hacker could potentially hack the database simply by typing SQL into the URL.
The other option available to you are SESSION variables. You will probably need cookies enabled to use session variables, and you need to have session_start() at the top of each page that uses the variables:
session_start();
$_SESSION['var1'] = 10;
$_SESSION['var2'] = 4;
$_SESSION['var3'] = 7;
$_SESSION['var4'] = "Hello world!";
In page 2, you would refer to them in the same way:
echo $_SESSION['var1']; // Outputs "7" to the screen
Normally, you would use session variables for values with a session-long life, like a user name or access level.