Simple PHP question - non geek here

Discussion in 'PHP' started by JustWorth, Apr 6, 2008.

  1. #1
    Hi

    I'm looking for a simple solution that will show a html / php web page for X number of views - after that it will show another page.

    The logic goes like this

    When someone clicks on the landing page url, the page code will
    - Read from a text file, the views count, views limit, page 1 url detail, page 2 url detail
    - If views count is less than or equal to the limit
    * Add 1 to e views count, write back to text file, then show page 1
    - If views count is more than the limit
    * Show page 2

    Help appreciated, thanks.
     
    JustWorth, Apr 6, 2008 IP
  2. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    list($pageonecount, $maxviews, $url1, $url2) = file('stats.txt', FILE_IGNORE_NEW_LINES);
    if ($pageonecount <= $maxviews) {
    	$pageonecount++;
    	$o = fopen('stats.txt', 'w');
    	fwrite($o, implode("\n", array($pageonecount, $maxviews, $url1, $url2)));
    	fclose($o);
    	// Show page one?
    	include $url1;
    } else {
    	include $url2;
    }
    PHP:
    Something like that?
    Not sure how you wanted to 'show' the pages. Text file would be something like:
    0
    100
    file1.html
    file2.html
    Code (markup):
    (separated by lines)
     
    decepti0n, Apr 6, 2008 IP
    JustWorth likes this.
  3. JustWorth

    JustWorth Peon

    Messages:
    98
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    decepti0n : Thanks, that worked exactly as I wanted.

    Rep Added.
     
    JustWorth, Apr 6, 2008 IP