1

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.

2
  • Wish you would have made that more clear in the first place. For this, a MySQL query like 'UPDATE hit SET counter = counter + 1' is very appropriate. However, that's not a lot of information. Recommend installing an approach like Google Analytics, instead. Commented Apr 26, 2012 at 2:42
  • It's not for hitcounts, it's for whatever. The MySQL approach I've tried, as I said, but then you have to connect to it, select a DB, run a whole query, get the output.. It's a lot of functions. I'm ideally aiming for some sort of "permament" superglobal array. Commented Apr 26, 2012 at 2:44

2 Answers 2

1

I finally found the answer: apc_store et al

Sign up to request clarification or add additional context in comments.

Comments

0

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'];

1 Comment

Search for perhaps a more applicable approach, there's lots of existing answers that will help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.