Click here to Skip to main content
15,888,219 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I wanna ask if how can I regain the value of a variable in php when I will be redirected to another page.

Tnx
Posted

To set the var:

session_start();
$_SESSION['myVariable'] = $myVariable; 


To use the var in another page:

XML
session_start();
$myVariable = $_SESSION['myVariable'];




 
Share this answer
 
You can use a session variable, as John suggested, or you can use a get variable, by redirecting with the variable in the url.

Eg.
tosend.php
$var = 2;
header( 'Location: receive.php?var=' . $var );
receive.php
$var = $_GET[ 'var' ];
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900