How to use a variable contained in another PHP page?

9
Well, good afternoon. How do I use a variable from an X.php file on the Y.php page? I want to do, for example, the following:

<?php
    $Frase = "minha frase";
?>

On my Y page I want to get the value of one of these variables, eg:

<h3>
<?php $Frase; ?>

How could I receive the result of these variables from other pages? would anyone have an example?

    
asked by anonymous 16.11.2015 / 17:19

2 answers

5

Knowing that the file "other_file.php" has:

<?php
    $frase = "abcdef";
?>

In another file (from the same directory) you can include the variable as follows:

<?php
    include('outro_ficheiro.php');
    echo $frase;
?>
    
16.11.2015 / 17:31
1

By session.

PageX.php

<?php
    session_start(); # Deve ser a primeira linha do arquivo

    $frase = "Minha Frase";

    $_SESSION['frase'] = $frase;
?>

PageY.php

<?php
    session_start(); # Deve ser a primeira linha do arquivo

    echo $_SESSION['frase'];
?>
    
16.11.2015 / 17:23