Reputation: 197
I have a PHP code processing some data in index.php, and the result would be shown in a variable called "$output". Would it be possible to show the variable in another PHP page (i.e. result.php)? Many thanks for help.
index.php
$output .= ''.$A.', '.$B.', '.$C.'';
result.php
showing the data from $output
Upvotes: 0
Views: 51
Reputation: 7783
Your question is very general, so it depends on your use case. But, for result.php
to be able to access $output
(or at least the data that it was originally assigned) you need to choose a way to persist that data. Here are some common ones:
result.php
inside index.php
(not exactly persisting data, but loading the result page in the same request)The most simple for what I think you want is to use sessions.
Upvotes: 1
Reputation: 743
Many way you can show this
<?php
session_strat();
$_SESSION['OUTPUT'] = $A.','.$B.','.$C;
?>
result.php
<?php
session_strat();
echo $_SESSION['OUTPUT'];
?>
Upvotes: 0
Reputation: 127
You can use include
:
index.php:
$output .= ''.$A.', '.$B.', '.$C.'';
result.php:
include_once 'index.php';
echo $output; // whatever you need to do with $output
Upvotes: 0
Reputation: 2995
use session
In your index.php
session_start();
$_SESSION["output"] =$output;
In your result.php
session_start();
if(isset($_SESSION["output"]))
{
echo $_SESSION["output"];
}
Upvotes: 1
Reputation: 514
You have a lot of methods to do this.
I think that the most easy is use sessions.
index.php
session_strat();
$_SESSION['output'] .= ''.$A.', '.$B.', '.$C.'';
result.php
session_strat();
echo $_SESSION['output'];
Remember that you can get all the information of php in documentation, for example this in: http://php.net/manual/en/session.examples.basic.php
Upvotes: 0