60734

Own SuperGlobal Variable in PHP?

Question:

I was reading something about SuplerGlobals like $_SERVER or (see more detail <a href="http://php.net/manual/en/language.variables.superglobals.php" rel="nofollow">PHP Manual Superglobals</a>) the other day, now, I'm asking me:

Is it possible to implement own SuperGlobals? Beside of Constants...

So for example user A writes something in the Variable which, if User B is calling it can see. Something like a server wide Session Variable or something.

Please don't be to hard, if its a silly question :) I know there are couple of ways outside, like SQL, Xml and Stuff, but maybe...

Answer1:

PHP doesn't have context which can be shared between users. You should some replacement like SQL server or file. You may also check some extensions like <a href="http://php.net/manual/en/book.memcache.php" rel="nofollow">memcache</a> which might help you achieve your goal.

Answer2:

Your whole idea of PHP superglobals it wrong.<br /> These variables are always available in terms of just one script runtime, no the whole site.

Answer3:

<blockquote>

I was reading something about SuplerGlobals like $_SERVER or (see more detail PHP Manual Superglobals) the other day, now, I'm asking me:

Is it possible to implement own SuperGlobals? Beside of Constants...

</blockquote>

Yes it is possible if you've got the <a href="http://php.net/manual/en/runkit.configuration.php" rel="nofollow">PHP runkit</a> extension.

<blockquote>

So for example user A writes something in the Variable which, if User B is calling it can see

</blockquote>

That's not what superglobals do - they are variables which exist in global scope (i.e. for the duration of an instance of a script).

If you want to share data between different invocations then you need to send it to your storage tier or (in the case of data for a single client) out to the browser.

Since what you are describing here is effectively a shared session, then the sensible place to implement this would be in the session handler.

Answer4:

This is not possible, you can only see your own session data.

To achieve this you would need to store the data somewhere else. in text files or in a MySQL database would be the most common.

Answer5:

i suppose you can use (asterix)export yourvar="something"(asterix) and to receive it using getenv

sry, dont know how to embed asterix=`, but it is better to avoid it...

If you use apache following could be used: <a href="http://php.net/manual/en/function.apache-setenv.php" rel="nofollow">http://php.net/manual/en/function.apache-setenv.php</a>

same idea, enveroinment variable

Recommend

  • Why am I getting invalid_grant for Google API calls from App Engine?
  • Multiple Servers And Memcached
  • memcache won't store key/value because the value is too big
  • Why am I getting an error in my ASP.NET Core SQL Server Express Connection String?
  • Java Caching frameworks for maintaining huge data
  • How do I chomp a string if I have Perl 4?
  • javascript Confirm replacement with return true/false
  • Insert space after period using sed
  • Firefox extension testing and developing - I'm confused
  • goJS dropdown remove items
  • Use sed with regex and (
  • Less Conflicting Session Manager for Zope 2
  • How to pass a value from ASP.NET MVC controller to ASP.NET webforms control inside MVC View?
  • Possible to “watch” both HAML and SASS at the same time?
  • Ubuntu and bcrypt
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • pyodbc doesn't report sql server error
  • Alternative To body {overflow:scroll;} That Will Prevent Page Jostling/Wriggling?
  • Play WS (2.2.1): post/put large request
  • Setting up SourceTree to merge unity3d scenes with UnityYAMLMerge
  • why do I get the error when installing the gem 'pg'? [duplicate]
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • Recording logins for password protected directories
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Splitting given String into two variables - php
  • PHP - How to update data to MySQL when click a radio button
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Counter field in MS Access, how to generate?
  • Check if a string to interpolate provides expected placeholders
  • Cassandra Data Model
  • Deserializing XML into class C#
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • Is there a mandatory requirement to switch app.yaml?
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Angular 2 constructor injection vs direct access
  • coudnt use logback because of log4j
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How to Embed XSL into XML