Jump to content

Basic PHP Help!


satl

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.