Global Variables used across files in PHP [closed]
I have come across a situation where i need to use a queue and that should be accessible in all the pages . I tried it using Global variables but couldn't meet the requirement.
If it isn't constant data, you coud use a session var
some_page.php
<?php
session_start(); //Never forget this line when using $_SESSION
$_SESSION['queue'] = "my queue value";
?>
other_page.php
<?php
session_start(); //Never forget this line when using $_SESSION
$queue = $_SESSION['queue'];
//use queue for your needs
?>
If it's constant data, you could put its value in a php file, and include it where you need.
queue.php
<?php
$queue = "my queue value";
?>
some_file.php
<?php
require_once "queue.php";
echo $queue;
?>
Hope this helps
Create object (write class), where this queue will be stored, and pass this object (variable) into all methods/functions, where this queue is needed.
You could use a (my)sql(ite) database to store your queue. It is super persistent and, once you get the hang of it, super easy to use.
精彩评论