Question

I would like to show different block every second pageview in the sidebar. Unfortunately, the WordPress by default does not utilize sessions. Is there any other way to track the same user's hits without utilizing sessions? It would be enough to know, if it is first, second, n-th users pageview this visit.

Thanks! Jonas

Was it helpful?

Solution

There's a way to do it without sessions but it's pretty lame (using IP and DB). You'll need some PHP code & database.

+Table: visits

  • id
  • ip
  • visit_time
  • is_second_pageview

1.Someone visits a page on your site , the script will insert to the table the next values:

  • The visitors IP (you can get it with php $_SERVER variable)
  • current time (you can use time() function)
  • 1

2.The script will check if the visitor's IP already exists in the DB and will also check the value of the matched field "is_second_pageview" , if this value is 1 then it's the seconds pageview , otherwise it's the 3rd , 5th , ... pageview. The script then will update the value of that field to 0 and show an ad to your request.

3.Use cron job to delete old rows (according to the visit_time field), otherwise this table will be over-populated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top