jiten2015
jiten2015

Reputation: 197

Showing PHP variable in another page

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

Answers (5)

LeonardChallis
LeonardChallis

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:

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

Upvotes: 1

debasish
debasish

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

Or Med
Or Med

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

Manjeet Barnala
Manjeet Barnala

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

Miguel Jim&#233;nez
Miguel Jim&#233;nez

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

Related Questions