Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: anyway to make my script count itself?

  1. #11
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,951
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    To do that with javascript alone you would have to make up an array of 36 or more links for each day of the week (7 arrays), or each day of the month (31 arrays).

    But if you were to go partially or fully server side, you could have a random set of links from a single huge array and have that set of links change on a daily basis until all were all used up, then start over from the complete list.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  2. #12
    Join Date
    Jun 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    but would i be able to keep them as links?

    Code:
    <a href="[site]>[desc]</a>
    or would it be just a list of [sites] only?


    also...i thought there was a way to use the links on a daily basis until all were used up using a js script...

    possibly changing the (randomlink.length ) code to something different?

    you could have a random set of links from a single huge array and have that set of links change on a daily basis until all were all used up, then start over from the complete list.
    this is exactly what im looking to do

  3. #13
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,951
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    For that last, you would have to go server side. The only way to do it in javascript alone would involve persistent cookies and/or local storage, but folks could delete those/that or not accept them in the first place. Even if they didn't choose to, default data limits on some browsers might make it break down.

    When I have a bit more time I will draw something up for a server side approach. But you will need a host that runs server side code. I can do PHP, possibly asp. I prefer PHP. Does your host have PHP available to you?

    Oh, and - Yes, server side code can supply full links on the page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #14
    Join Date
    Jun 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    For that last, you would have to go server side. The only way to do it in javascript alone would involve persistent cookies and/or local storage, but folks could delete those/that or not accept them in the first place. Even if they didn't choose to, default data limits on some browsers might make it break down.

    When I have a bit more time I will draw something up for a server side approach. But you will need a host that runs server side code. I can do PHP, possibly asp. I prefer PHP. Does your host have PHP available to you?

    Oh, and - Yes, server side code can supply full links on the page.
    PHP 5.2 or 5.3

    Thank you very much...

    I will check into PHP as well. I learned some PHP in school but not using it, it has faded...

  5. #15
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,951
    Thanks
    43
    Thanked 3,195 Times in 3,157 Posts
    Blog Entries
    12

    Default

    OK, here's the main code:

    PHP Code:
    <?php
    $numlinks 
    5//set to number of links to display today - this number should evenly divide into the number of links listed in the $masterfile
    $masterfile 'masterlinks.txt'//create and maintain this file yourself, list one link per line, no blank lines, except one at the end
    $currentfile 'currentlinks.txt'//do not create or maintain this file, the script will do that
    $dayfile 'day.txt'//do not create or maintain this file, the script will do that
    clearstatcache($dayfile);
    $day is_file($dayfile)? date("j"filemtime($dayfile)) : 0;
    $today date("j");
    clearstatcache($currentfile);
    //ini_set("auto_detect_line_endings", true); //uncomment this line if $masterfile was made on a Mac, or server is a Mac
    $currentlinks is_file($currentfile)? file($currentfile) : null;
    if(!
    $currentlinks || count($currentlinks) < $numlinks){
        
    copy($masterfile$currentfile);
        
    $currentlinks file($currentfile);
    }
    if(
    $day !== $today){
        
    shuffle($currentlinks);
        
    $todaylinks array_splice($currentlinks0$numlinks);
        
    file_put_contents($dayfile$todaylinks);
        
    file_put_contents($currentfile$currentlinks);
    }
    echo 
    implode("<br>\n"file($dayfileFILE_IGNORE_NEW_LINES));
    ?>
    As commented, you only have to make up and maintain the $masterfile (masterlinks.txt in this case). You can change the filenames to suit and include paths if desired. If you do, use the server path to the file, not the URL path. But there's no need to change them. As is the masterlinks.txt file would go in the same folder as this file or, if this file is included on another page, in the same folder as that page.

    The masterlinks.txt file should have 1 link per line in ordinary HTML code, ex:

    Code:
    <a href="http://www.google.com/search?hl=en&amp;rls=en&amp;q=bob">Bob</a>
    <a href="http://www.google.com/search?hl=en&amp;rls=en&amp;q=carol">Carol</a>
    <a href="http://www.google.com/search?hl=en&amp;rls=en&amp;q=ted">Ted</a>
    <a href="http://www.google.com/search?hl=en&amp;rls=en&amp;q=alice">Alice</a>
    <a href="http://www.google.com/search?hl=en&amp;rls=en&amp;q=jquery">jQuery</a>
    <a href="http://www.google.com/search?hl=en&amp;rls=en&amp;q=scriptaculous">Scriptaculous</a>
    There should be no blank lines except that the last line should be blank. In other words, there should be a line break at the end of each line that has a link on it. You can use any valid HTML code for a link, including one that contains an image instead of text as the link trigger. Don't quote these links like entries in an array, just write them as normal HTML code, one per line. Image and link paths should be valid for the page that the images and links will appear on. When in doubt, use the absolute path.

    The only other thing to configure is the number of daily links ($numlinks). I used 5 as I only had 30 links in my masterlinks.txt file. Unless you want some links to be missed on occasion, that is after going through them all on a day to day basis and resetting because there aren't enough for the last day, use a $numlinks value that evenly divides into the number of links in the masterlinks.txt file. If you don't make it evenly divisible, the links that are missed will be potentially different each cycle, but as luck might have it, one or more might get missed a lot. It's a random algorithm, not a unique one.

    Oh, and notice the ini_set() command. It's commented out. The manual said to use that for files created on a Mac and/or for Mac servers. But it also said not to unless there were problems with detecting EOL (line breaks). You will know if that happens if everything else is set up correctly and things still don't work.

    Any questions, just let me know.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. How to make Javascript count-up timer ?
    By k12onos in forum JavaScript
    Replies: 6
    Last Post: 03-27-2012, 11:57 PM
  2. Looking for a count up script
    By darmie_a_Phoenix in forum Dynamic Drive scripts help
    Replies: 24
    Last Post: 03-22-2010, 06:08 PM
  3. Count down script
    By Scrounger in forum Dynamic Drive scripts help
    Replies: 9
    Last Post: 08-08-2007, 09:29 PM
  4. Count Up Script
    By Dan6971 in forum JavaScript
    Replies: 1
    Last Post: 09-07-2005, 03:58 PM
  5. Count Down Script
    By kjenkins in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 12-10-2004, 09:45 PM

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
  •