开发者

Global Variables used across files in PHP [closed]

It's difficult to tell what is being asked here. This question is a开发者_开发知识库mbiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜