0

I need to create a centralized page where all the variables that are needed in more than one page get set. For example:

centralized.php

$displayPath = "/var/www/html/wordpress/";

Then, I need html and php pages across the server to have access to it. For example:

page1.html

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
</body>
</html>

<?php
echo ($displayPath);
?>

page2.php

<?php
echo ($displayPath);
?>

I was looking at using window.localStorage, but when doing so, how could pass the value from JS variables to php variables.

1 Answers1

0

If you only want to read the variables from different pages, you can create a file with all of your variables:

myVariables.php

<?php
    $displayPath = "/var/www/html/wordpress/";
    $myglobalvariable="hello";
?>

And then include it in every page that needs it.

page1.php

<?php
    require_once("./myVariables.php");    
?>

NOTE: This will not allow you to change the variables in one page and then access the modified variables in another page. If that's what you want, you can take a look at this:

How to access a variable across two files

clod9353
  • 1,942
  • 2
  • 5
  • 20