Free php scripts


Article Submission
  • Register
  • Login


  • Tutorials/support/References
  • PHP/ASP/PERL Bookstore
  • Community
  • Chat
  • Tutorials
  • Free Smiley Icons
  • Web Hosting

  • Search


    Scripts
  • Chipmunk CMS
  • Forums PHP Script
  • Chipmunk Blogger Script
  • Chipmunk Topsites
  • Chipmunk Addresshost
  • Chipmunk Newsletter
  • Free Guestbook Script
  • Free Poll Script
  • Directory Script
  • Kill Monster
  • Free FFAL script
  • CMS core
  • Chat Room
  • Riddles
  • Random Links
  • Recommend Site
  • Random Quote
  • Story Lines
  • Text Counter
  • Chipmunk Live
  • Chipmunk Bloghost
  • PHP AWS script
  • pwngame
  • Books
  • Begginning PHP4
  • Professional PHP4
  • PHP Cookbook
  • Legal Stuff for scripts
  • Script Liscense


  • Top 5 hottest members
    Chipmunk




    Quality Freelancing


    Sister Sites
  • My Blog
  • Albino Freebies
  • Java gaming
  • Flashninjaclan


  • Premium Affiliates
     
     
    Counter tutorial

    This simple tutorial will explain how to program a simple text-file counter.
    Creating a simple counter requires you do three things:

  • Open up a file and read current count value.
  • Add one to the current value.
  • Read and print the new value.
    So for the this tutorial, first create a file called sample.php and put a 0 in it as a default start point.
    Now the actual code for the counter:


    <?php
    //tutorial for text-file based counter
    $counthandle=fopen("sample.php","r");
    //opens file for reading and writing
    $getcurrent=fread($counthandle,filesize("sample.php"));
    //reads in current value
    $getcurrent=$getcurrent+1;
    //increment count by 1
    fclose($counthandle);
    $counthandle1=fopen("sample.php","w");
    fputs($counthandle1,$getcurrent);
    //input new value
    fclose($counthandle1);
    $counthandle2=fopen("sample.php","r");
    $getrecent=fread($counthandle2,filesize("sample.php"));
    //gets new value
    print "$getrecent";
    //print counter value
    fclose($counthandle2);
    ?>

    The comments are provided below each line tell what the line above does.
    First the "$counthandle" variable opens up your sample.php file which you created for reading.
    The freads function reads whatever is in sample.php and stores it in $getcurrent. fclose() closes file handles. The $counthandle1 opens up the sample.php file for writing. We already incremented $getcurrent by one before hand so now we use fputs to write the new value over the old value we had. Finally, $counthandle2 opens the new sample.php and reads the new file and stores it in the $getrecent variables. The last line simple prints whatever is in $getrecent.
    A example is provided below:

    This tutorial has been viewed 5344 times.
  • News Categories
  • Site News
  • Technology news
  • Programming news
  • Other Major News


  • Search Articles


    Make Money
    Free Blog promotion -- Get your blog syndicated on thousands of other blogs for free.

    Tutorial Categories
    Ad Managers(5)
    Calendars(6)
    Chat systems(5)
    CMS systems(7)
    Cookies/Sessions(4)
    Counters(8)
    E-commerce(7)
    File Manipulation(4)
    Forms(10)
    Forums(4)
    Guestbooks(5)
    HTML/CSS Tutorials(12)
    Image-related(5)
    Link indexing/ Classifieds(6)
    Mailing Lists/E-mail(5)
    Misc(17)
    MySQL Related(9)
    Navigation/Templating(6)
    PHP Basics(10)
    Polls(3)
    RSS and other feeds(5)
    Searching(4)
    Security(13)
    XML and other parsing(3)


    Resources
    Scripts/Graphics
  • Ecommerce Website Design
  • Hotscripts
  • Boxedart
  • Zero Web
  • Edorel Free Hosting
  • Javascript Reference
  • Powerful Scripts
  • Scripts Bank
  • Finestzone Designs
  • Layouts 4 free
  • Website Resources
  • 4 templates
  • Free URL redirection
  • Web Hosting
  • Website Hosting
  • Photoshop Tutorials
  • PHP and MYSQL tutorials
  • Free Templates
  • Tutorials DB
  • Pure Graphics
  • Total Tutorials
  • Myspace Pro Designs
  • Texas Electric Service
  • Cirro Energy
  • Reliant Energy Houston


  • Random Affiliates
        
        
        

    More affiliates