How do I get variable to a PHP file from another PHP-file?

 You can pass a variable from one PHP file to another by including the first file in the second file using the include or require statement and then accessing the variable with the global keyword.

For example:

File: first.php

$variable = "value";

File: second.php

include 'first.php';

echo $variable;

You can also pass variables between PHP files using the session, cookie or query string. The query string method involves adding the variables to the URL when redirecting to the second page.

Comments

Popular posts from this blog

Can a PHP website be shared with another Windows machine?