Hi
I have trying to find a way to count the amount of page views within the iframe, is it possible to do? I know it is possible outside of iframe in php... basically i want it to goto another URL after 5 page views. Any ideas?
Hi
I have trying to find a way to count the amount of page views within the iframe, is it possible to do? I know it is possible outside of iframe in php... basically i want it to goto another URL after 5 page views. Any ideas?
Since you can use a regular url for a iframe and considered using php, why bother with javascript?
As I understand you want to count ALL iframe-page-visits.
<iframe src="page123.php" ...
page123.php with a very simple counter:
Code:<?php //there can't be anything before this. //No space, no linebreak, no html, due to the header redirect! if(!file_exists("count.txt")) {$counter=fopen("count.txt", "a");} else {$counter=fopen("count.txt", "r+");} $filedo=fgets($counter,100); $filedo=$filedo+1; rewind($counter); fputs($counter,$filedo); fclose($counter); if($filedo>4) {header('Location:SOMEOTHERPAGEURL.htm');} else if($filedo>4) {header('Location:SOMEOTHERPAGEURL2.htm');} ?>
I'd go with sessions over an actual file.
Source code of the PHP file called by the iFrame:
Or, possibly even cookies.. Cookies will rely on user settings though. Sessions rely strictly on server settings, so given all your server settings are okay to use sessions, that very small script will be perfect for what you're using. Also, the session will be wiped upon a duration of inactivity and/or a browser restart.Code:session_start(); if(!$_SESSION['counter']) $_SESSION['counter'] = 0; $_SESSION['counter']++; if($_SESSION['counter'] == 5) header("Location: counterabove5.html"); else header("Location: counterbelow5.html");
Of course, then a file (or mysql entry) would not be needed.
I thought playzfer wanted to redirect different users that visited the page, not the same person that visits a page again.
Bookmarks