Reputation:
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.
Upvotes: 1
Views: 356
Reputation: 63845
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.
Upvotes: 1
Reputation: 10095
if you use something like memcached, you can store any value into it. it will work like very global and very static variable
Upvotes: 0
Reputation: 3553
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
Upvotes: 2
Reputation: 4977
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.
Upvotes: 1
Reputation: 351536
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.
Upvotes: 5