suigion Posted August 22, 2007 Share Posted August 22, 2007 hi all, How do I copy variable from one page to another page in PHP? For example: I want to put a $var in page A into page B. Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/66096-how-to-copy-a-variable-from-one-page-to-another-page/ Share on other sites More sharing options...
keeB Posted August 22, 2007 Share Posted August 22, 2007 a.php <?php session_start(); $_SESSION['var'] = "next page"; echo '<a href="b.php">b</a>'; ?> b.php session_start(); print $_SESSION['var']; Quote Link to comment https://forums.phpfreaks.com/topic/66096-how-to-copy-a-variable-from-one-page-to-another-page/#findComment-330547 Share on other sites More sharing options...
clearstatcache Posted August 22, 2007 Share Posted August 22, 2007 try to use session...put the cmd session_start() at the beggining of ur code... in page A code <?php session_start(); $_SESSION['var'] = $var; ?> to retrieve thje var in page B: <?php $var = $_SESSION['var']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/66096-how-to-copy-a-variable-from-one-page-to-another-page/#findComment-330549 Share on other sites More sharing options...
johlwiler Posted August 22, 2007 Share Posted August 22, 2007 Make sure when you start the session (session_start() it is one of the first things on the page. The session has to be started before anything is sent to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/66096-how-to-copy-a-variable-from-one-page-to-another-page/#findComment-330679 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.