satl Posted January 19, 2009 Share Posted January 19, 2009 I have searched for hours, trying to figure this out. Please help me. I barely understand PHP. I want to have a php page that contains all the variables, so I'm guess it would look something like this, I'm not really sure: <body> <?php $var1 = 10; $var2 = 4; $var3 = 7; $var4 = Hello World; ?> </body> Then, I simply want to display those variables on another php page. Could you tell me what exactly is the code I need to display one of the above written variables? Thanks, Shane Link to comment https://forums.phpfreaks.com/topic/141519-basic-php-help/ Share on other sites More sharing options...
ratcateme Posted January 19, 2009 Share Posted January 19, 2009 you need sessions LIKE page1.php: <?php sessions_start(); //MUST BE BEFORE ANY OUTPUT AS IT SENDS HTTP HEADERS ?> <body> <?php $var1 = 10; $var2 = 4; $var3 = 7; $var4 = Hello World; $_SESSION['var1'] = $var1; $_SESSION['var2'] = $var2; $_SESSION['var3'] = $var3; $_SESSION['var4'] = $var4; ?> <a href="page2.php">page2</a> </body> page2.php: <?php session_start(); ?> <body> <?php $var1 = $_SESSION['var1']; $var2 = $_SESSION['var2']; $var3 = $_SESSION['var3']; $var4 = $_SESSION['var4']; //different ways to output vars with strings echo "var1 = " . $var1 . " <br>"; echo "var2 = $var2 <br>"; echo "var3 = {$var3} <br>"; echo 'var4 = '.$var4.'<br>'; ?> </body> Scott. Link to comment https://forums.phpfreaks.com/topic/141519-basic-php-help/#findComment-740778 Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 inc.php <?php $var1 = 10; $var2 = 4; $var3 = 7; $var4 = "Hello World"; ?> page.php <?php include "inc.php"; echo $var1; echo $var2; echo $var3; echo $var4; ?> Link to comment https://forums.phpfreaks.com/topic/141519-basic-php-help/#findComment-740780 Share on other sites More sharing options...
satl Posted January 19, 2009 Author Share Posted January 19, 2009 inc.php <?php $var1 = 10; $var2 = 4; $var3 = 7; $var4 = "Hello World"; ?> page.php <?php include "inc.php"; echo $var1; echo $var2; echo $var3; echo $var4; ?> Thank you, that did it! Link to comment https://forums.phpfreaks.com/topic/141519-basic-php-help/#findComment-740788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.