Read variable in other includes php

I have 2 pages, Home.php and re.php. How do I call variable $very from home.php to re.php? I tried

<?php echo $very; ?>

but it's not working.. or do u have other idea?

    $very = 'verifytrans-1.php';
    include_once 're.php';

2 answers

  • answered 2018-01-14 11:32 Goms

    In your re.php file, use something like

    require_once 'home.php';
    echo $query;

    But, to have a convenience help, you need to explain exactly what you want.

  • answered 2018-01-14 12:04 CaffeinatedTech

    Including a file in PHP essentially pulls in the code from that file into the current file at run time. So variables that you define before the 'include' will be available to use normally in the included file.

    So in your re.php file, just use the $very variable normally.

    It looks like you are using <?php echo $very; ?> inside PHP code in your re.php. You only need to do that in HTML, just use $very instead.

    Another problem is that you may be trying to access a global variable inside a function. You need to either pass the variable to the function, or invite it into the function scope using global $very;


    $very = 'verifytrans-1.php';
    include_once 're.php';


    function redirect() { 
      global $websiteurl;
      global $very;
      $this->variable['redirect_url'] = $websiteurl . $very;
      return $this;