SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Nov 2000
    Posts
    740
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Rotating webpage headline

    I have a webpage that looks like a sales letter. To test different headlines for their sales pulling power, I want to rotate several headlines.

    Ideally, they should be sequential. i.e. i would have 4 headlines, for example, and would appear Headline 1, 2, 3 and then 4. On the 5th visitor, Headline 1 would then appear. Get my drift?

    What is the best way to achieve this?

    My php is a little rusty but I'm learning hard!

    Thanks,

    Jon

  2. #2
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could have a file that contains the headline number (kinda like the text-file based counters). Each time the page is loaded, it reads in the contents of this file and updates the number... if (++$i > 4) { $i = 1; } ... and you could use that number as an index to an array or something that contained your headlines...

  3. #3
    SitePoint Guru
    Join Date
    Nov 2000
    Posts
    740
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Almost there!

    Thanks for that tip.

    I've now got a page that will rotate my headlines - result!! But the goal posts have now changed.

    What I would like is to have 3 different webpages: index1.htm, index2.htm, index3.htm

    When someone goes to my index.php page, it loads up index1.htm as the page. The next visitor gets index2.htm and so on. Exactly the same as rotating the headlines but instead it is for changing the entire body copy.

    My code is as follows...

    <?php
    //Simple PHP headline swapper
    if (file_exists('count.inc'))
    {
    $fil = fopen('count.inc', r);
    $dat = fread($fil, filesize('count.inc'));

    $headlines=array("Hello world","Hello England","Hello me");

    echo ($headlines[$dat]);
    if (++$dat > 2) { $dat = 0; }

    fclose($fil);
    $fil = fopen('count.inc', w);
    fwrite($fil, $dat);
    }
    else
    {
    $fil = fopen('count.inc', w);
    fwrite($fil, 1);
    echo '1';
    fclose($fil);
    }

    ?>

    How can I adapt this to get it to read in and display the files index1.htm etc. ?

    Thanks,

    Jon

  4. #4
    code addict Abstraction's Avatar
    Join Date
    Apr 2001
    Location
    Des Moines, IA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php 
    //Simple PHP headline swapper 
    if (file_exists('count.inc')) { 
    $fil fopen('count.inc'r); 
    $dat fread($filfilesize('count.inc')); 

    $page "index." $dat ".htm";

    include (
    $page);

    if (++
    $dat 2) {
    $dat 0;


    fclose($fil); 
    $fil fopen('count.inc'w); 
    fwrite($fil$dat); 
    } else { 
    $fil fopen('count.inc'w); 
    fwrite($fil1); 
    echo 
    '1'
    fclose($fil); 


    ?>
    The syntax may be a tad off, but that's the general idea.


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
  •