0

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
2
  • 2
    One word: PHP $_SESSION Commented Apr 13, 2016 at 9:50
  • make $output as a global variable to use. Commented Apr 13, 2016 at 9:50

5 Answers 5

1

use session

In your index.php

session_start();
$_SESSION["output"] =$output;

In your result.php

session_start();
if(isset($_SESSION["output"]))
{
    echo $_SESSION["output"];
}   
Sign up to request clarification or add additional context in comments.

Comments

1

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:

The most simple for what I think you want is to use sessions.

1 Comment

Using get or post method
0

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

Comments

0

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

Comments

0
Many way you can show this
<?php
session_strat();
$_SESSION['OUTPUT'] = $A.','.$B.','.$C;

?>
result.php
<?php
session_strat();
echo $_SESSION['OUTPUT'];
?>

2 Comments

While this code may answer the question, providing additional context regarding why and/or how it answers the question would significantly improve its long-term value. Please edit your answer to add some explanation.
session_strat() is not a function either

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.