PHP: Only show page once

5 replies
Iam working on some one time offers that I want to only show once (ie: if they refresh the page, or try to load the oto page at a later date, it will not be availabe to them)

I had this script sitting on my hard drive for the longest time and now after almost an hour of searching I can't find it anymore, can't find it via Google either

I think what it did was record the user's IP address to a text file so that when the oto page loaded it would compare their IP address to those recorded in the text file.

Best regards
~ Ross
#page #php #show
  • Profile picture of the author apoorv.parijat
    Here is the script.Wrote it for you.

    You need to create a "log.txt" file in the same directory and change its permission to writable.I could have inserted a line to create this file but sometimes web hosts disable file creation through PHP.

    Hope this helps.

    Cheers

    <?php
    $dateTime = date('Y/m/d G:i:s');
    $fp = fopen('log.txt', 'r+');
    if(!$fp){
    echo "Log file doesn't exists.";
    }
    else{
    $visited = FALSE;
    while (!feof($fp))
    {
    $buffer = fgets($fp);
    list ($ip, $time) = split(' ', $buffer);
    //Checks if IP is already logged.
    if ($_SERVER['REMOTE_ADDR'] == trim($ip))
    $visited = TRUE;
    echo "Not your first visit.";

    }
    if (!$visited){
    fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\n");
    echo "First visit.";
    }
    fclose($fp);
    }
    ?>
    {{ DiscussionBoard.errors[2011701].message }}
    • Profile picture of the author webtrix
      And here's a simple code to check if a proxy is used

      if ($_SERVER['HTTP_X_FORWARD_FOR'])
      {
      $IP = $_SERVER['HTTP_X_FORWARD_FOR'];
      } else {
      $IP = $_SERVER['REMOTE_ADDR'];
      }
      {{ DiscussionBoard.errors[2012058].message }}
  • Profile picture of the author Spinethetic
    Wicked! Thanks for the script, almost done with one oto and Ill be poutting this in there.

    And there are many good uses for detecting proxies, but I think that if my optins are that desperate (what with some of the questionable advertising integrated into them and God knows what else...) to take a second look at my oto through a proxy, than Ill just let them get a second look haha
    {{ DiscussionBoard.errors[2012113].message }}
    • Profile picture of the author apoorv.parijat
      Originally Posted by Spinethetic View Post

      Wicked! Thanks for the script, almost done with one oto and Ill be poutting this in there.

      And there are many good uses for detecting proxies, but I think that if my optins are that desperate (what with some of the questionable advertising integrated into them and God knows what else...) to take a second look at my oto through a proxy, than Ill just let them get a second look haha
      You are welcome. I uploaded the script here.

      www.salescanvastheme.com/notwice.php

      for testing purpose.Works clean.

      Cheers
      {{ DiscussionBoard.errors[2014335].message }}
      • Profile picture of the author apoorv.parijat
        Script update.I realised,message "Not first visit." has to be inside conditional.Fixed now.

        <?php
        $dateTime = date('Y/m/d G:i:s');
        $fp = fopen('log.txt', 'r+');
        if(!$fp){
        echo "Log file doesn't exists.";
        }
        else{
        $visited = FALSE;
        while (!feof($fp))
        {
        $buffer = fgets($fp);
        list ($ip, $time) = split(' ', $buffer);
        //Checks if IP is already logged.
        if ($_SERVER['REMOTE_ADDR'] == trim($ip)){ << '{' where missing
        $visited = TRUE;
        echo "Not your first visit.";
        } added '}'
        }
        if (!$visited){
        fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\n");
        echo "First visit.";
        }
        fclose($fp);
        }
        ?>
        {{ DiscussionBoard.errors[2014351].message }}

Trending Topics