Results 1 to 5 of 5

Thread: Iframe Question

  1. #1
    Join Date
    Sep 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Iframe Question

    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?

  2. #2
    Join Date
    Sep 2008
    Posts
    26
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    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');}
    
    ?>

  3. #3
    Join Date
    Sep 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'd go with sessions over an actual file.

    Source code of the PHP file called by the iFrame:
    Code:
    session_start();
    
    if(!$_SESSION['counter']) $_SESSION['counter'] = 0;
    $_SESSION['counter']++;
    
    if($_SESSION['counter'] == 5) header("Location: counterabove5.html");
    else header("Location: counterbelow5.html");
    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.

  4. #4
    Join Date
    Sep 2008
    Posts
    26
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    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.

  5. #5
    Join Date
    Sep 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by schorhr View Post
    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.
    Hmm... I took it the other way but it's really not clear. I guess either way, he's got a solution now

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •