Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    16
    Member #
    31024
    I have some counters in my html website that count up but that start at 1 instead of 0. I have the counter set up through php and .dat files. Any ideas what might be causing this? here is some code from the php file:

    <?php

    /* Subject and Email Variables */

    $emailSubject = 'I Pledge';
    $webMaster = '<REMOVED FROM POST>';

    /* Gathering Data Variables */

    $emailField = $_POST['email'];
    $stateField = $_POST['state'];
    $districtField = $_POST['district'];
    $zipcodeField = $_POST['zipcode'];
    $nameField = $_POST['name'];
    $cf = "counter.dat";
    $fp = fopen($cf,"r");
    $ct = trim(fread($fp,filesize($cf)));
    if (isset($ct)) $ct++;
    else $ct = 0;
    @fclose($fp);
    $fp = fopen($cf,"w");
    @fputs($fp,$ct);
    @fclose($fp);
    $body = <<<EOD
    <br><hr><br>
    Email: $emailField <br>
    State: $stateField <br>
    District: $districtField <br>
    zipcode: $zipcodeField <br>
    Name: $nameField <br>
    EOD;

    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $success = mail($webMaster, $emailSubject, $body, $headers);

    /* Results rendered as HTML */

    $theResults = <<<EOD
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>

    <body>
    <p>Your email has been sent</p>
    <p>&nbsp;</p>
    </body>
    </html>
    EOD;
    echo "$theResults";

    ?>

    Here is some code from the visual counter on my html page:

    <?php
    $cf = "counter.dat";
    $fp = fopen($cf,"r");
    $ct = trim(fread($fp,filesize($cf)));
    if ($ct != "0") $ct++; else
    $ct = 0;
    @fclose($fp);
    echo "pledges: ".$ct;
    ?>

  2.  

  3. #2
    WDF Staff George Dolidze's Avatar
    Join Date
    Apr 2011
    Location
    Irvine, CA
    Posts
    2,487
    Member #
    27540
    Liked
    416 times
    Well, when you view it, it counts as a visit. So I don't think it can ever be 0.
    My freelancer website: DolidzeDesign



    You only need a parachute if you plan on skydiving twice.

  4. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    16
    Member #
    31024
    It's not a hit counter, it is a form submission counter.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,716
    Member #
    5580
    Liked
    718 times
    if ($ct > 0) $ct++; else
    $ct = 1;



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:21 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com