DanRedux
DanRedux

Reputation: 9349

PHP Server-local Variable?

Short and sweet, I need to have a variable NOT be unset after a page has finished loading. I've used a file to store the value, and I've used a MySQL table with 1 record, and updated/read from that, but I want something cleaner and simpler. Any ideas?

Some people misunderstood the question, so here's an example. At the top of my page, I would have some code such as:

$_PERMANENT['hits']+=1;
print 'Hits: '.$_PERMANENT['hits'];

Note that this works across multiple clients, so it's not $_SESSION.

Upvotes: 1

Views: 98

Answers (2)

DanRedux
DanRedux

Reputation: 9349

I finally found the answer: apc_store et al

Upvotes: 1

zanlok
zanlok

Reputation: 1630

Use the $_SESSION, that's exactly what it's for. This either requires the user's browser has cookies on, or that you format links to maintain the session id.

At the start of your pages, use session_start() - only do this once, and it must be before content is written as it needs access to the header area.

session_register() is deprecated, so just do a $_SESSION['key'] = $value; and the next page load within that session will have access to the value via: $value = $_SESSION['key'];

Upvotes: 0

Related Questions