Is it possible to have true global variables in PHP? The tests I have done so far seem to suggest that you can have a global variable that is global only to the php file that declares it and not to your whole website. Once you go to another php file, the variable seems to loose what you assign it.

Recommended Answers

Use sessions or cookies or a db or a textfile or url or forms to pass data. Webpages are stateless, so no you don't get data from one page to another via 'normal' vars.

Jump to Post

All 2 Replies

Member Avatar

Use sessions or cookies or a db or a textfile or url or forms to pass data. Webpages are stateless, so no you don't get data from one page to another via 'normal' vars.

As ardav have pointed web pages are stateless. But yes you can have application scope static variables using database or file system and you can have also thread – visit static variables using session. Using these two deferent scope ways let you jump from stateless to state full.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.