tags:

views:

199

answers:

5

Hi,

I would want to display a certain message on a php page at a let's say 15 displayed pages. So it displays the message once and after 15 again and so on. I should need a varaible that keeps it's value between pages reload.

Can I do that with PHP?

thanks.

+4  A: 

Store the value in session:

Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.

Andrew Hare
+1  A: 

If you only want the value shown to one user, then the session is the way to go. If for more than one user, you'll need store the message on the server side in a file, database, etc. That said, it's not clear from your question what you're trying to achieve.

Parvenu74
+2  A: 

Alternatively to Andrew's answer:

If you want them to appear every 15 page views(not during a session) you have two options:

  • storing a counter in a database or file(both options will give you a bad performance)

  • using a statistical approach: generate a random number and by the chance of 1/15 display the message

André Hoffmann
A: 

if you use something like memcached, you can store any value into it. it will work like very global and very static variable

valya
+1  A: 

for such a simple piece of data as a counter, you could use a cookie or session. Though session(without using query strings) requires cookies anyway..

If you must do this without cookies or this needs to be global to all users, then you can store it in a database or file.

if appropriate though, you could possibly get by with putting the counter in query string and taking it on to all the links to these 15 pages.

Earlz