473,226 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,226 software developers and data experts.

Place Count number into form Variable or FormField

1
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below)

I want to place the current number into a variable $MemberNo or into a FormField to be sent via an email function.

But just can't figure it out.
Expand|Select|Wrap|Line Numbers
  1. <?
  2.  
  3. ////////////////////////////////////////////////////////////
  4. //
  5. // counter.php - a graphical counter
  6. //
  7. ////////////////////////////////////////////////////////////
  8. //
  9. // This script outputs a "hit count" displayed using digit
  10. // images and formatted according to the setting for
  11. // "minDigits".  The hit count can be incremented on every
  12. // page hit or only for unique IP addresses (the
  13. // "countOnce" feature).
  14. //
  15. // See help.txt for more information.
  16. //
  17. // Author: Jon Thomas
  18. // Last Modified: 7/13/01
  19. //
  20. // You may freely use, modify, and distribute this script.
  21. // You may remove this notice.
  22. //
  23. ////////////////////////////////////////////////////////////
  24.  
  25. // define the variables
  26. $file = "count.txt";    // text file that stores hit count
  27. $imgExtension = "gif";    // file extension of digit images
  28. $minDigits = 0;        // the minimum # of digits to display
  29.             // set to 0 to display only needed digits
  30. $countOnce = 0;        // set to 1 to count unique IPs only
  31.             // set to 0 to count all hits
  32. $ipFile = "Aips.txt";    // text file that stores IP addresses
  33.  
  34. // DO NOT EDIT BELOW THIS POINT UNLESS YOU KNOW PHP! //
  35.  
  36. // get the current hit count
  37. $fp_count = fopen($file, "r");
  38. $count = fread($fp_count, filesize($file));
  39. fclose($fp_count);
  40.  
  41. // if the "countOnce" feature is enabled
  42. if ($countOnce) {
  43.     // open the IP address file
  44.     $fp_ips = fopen($ipFile, "r");
  45.  
  46.     // compare each entry with the user's IP address
  47.     while (!feof($fp_ips)) {
  48.         // get an entry from the IP file
  49.         $ip = fgets($fp_ips, 20);
  50.  
  51.         // if the user's IP matches, set the user to old
  52.         if ($ip == $REMOTE_ADDR . "\r\n") {
  53.             $is_old = 1;
  54.             break;
  55.         }
  56.  
  57.         // otherwise, set the user to new
  58.         else {
  59.             $is_old = 0;
  60.         }
  61.     }
  62.  
  63.     // close the IP address file
  64.     fclose($fp_ips);
  65.  
  66.     // if the user is not old, add his IP to the IP file
  67.     if (!$is_old) {
  68.         // reopen the IP address file
  69.         $fp_ips = fopen($ipFile, "a");
  70.  
  71.         // add the user's IP address
  72.         fputs($fp_ips, $REMOTE_ADDR . "\r\n");
  73.  
  74.         // close the IP address file
  75.         fclose($fp_ips);
  76.     }
  77. }
  78.  
  79. // if the "countOnce" feature is disabled, set the user to new
  80. else {
  81.     $is_old = 0;
  82. }
  83.  
  84. // if the user is not old, increment the counter
  85. if (!$is_old) {
  86.     $count++;
  87.  
  88.     // save the new hit count
  89.     $fp_count = fopen($file, "w");
  90.     fputs($fp_count, $count);
  91.     fclose($fp_count);
  92. }
  93.  
  94. // count the number of digits in the hit count
  95. $digits = strlen($count);
  96.  
  97. // if minDigits is set and the number of digits is less than minDigits, add leading zeroes
  98. if ($minDigits && $digits < $minDigits) {
  99.     // find the difference between minDigits and the number of digits in the count
  100.     $diff = $minDigits - $digits;
  101.  
  102.     // add a number of leading zeroes equal to the difference
  103.     for ($i = 0; $i < $diff; $i++) {
  104.         $count = "0" . $count;
  105.     }
  106.  
  107.     // set digits equal to minDigits
  108.     $digits = $minDigits;
  109. }
  110. echo "<left>";
  111. // print the appropriate image for each digit in the hit count
  112. for ($i = 0; $i < $digits; $i++)
  113. {
  114.     // get a digit from the hit count
  115.     $digit = substr("$count", $i, 1);
  116.  
  117.     // print the image for that digit
  118.     echo "<img src=/images/new_digits/$digit.$imgExtension>";
  119. }
  120. echo "</left>";
  121. ?><body style="text-align: left">
Jul 24 '08 #1
1 3572
pbmods
5,821 Expert 4TB
Heya, JLT.

Try grabbing the $digits variable after you've run the counter script.
Jul 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Glyphman | last post by:
I have a bunch of pages with long forms, with lots of input types-text, radios, textareas, and the debugging process has become overwhelming. What I need to happen is to make sure that 1. Every...
10
by: KathyB | last post by:
Hi, I just can't get this quite right. I use the following function to validate a user entry. I need to allow negative numbers including those with decimals (e.g., -.5). The following allows the...
4
by: Er Galv?o Abbott | last post by:
Greetings. I have a function that does some pattern matching with JS's RegEx and I'm trying to use a variable inside of it. Nothing that I've done worked, so please help me. Here is the func:...
16
by: phpcode | last post by:
I have a javascript function as follows: function myfunction(formName,formField) { parseInt(document.formName.formField.value) +=1; } Then I can call the function when needed like this: ...
2
by: ashkaan57 | last post by:
Hi, I am trying to set some style, simeple ones, for some form fields and I don;t seem to get it working. in css file: ..FormField { font-size:x-small; font-family: Verdana, Arial,...
10
by: John Salerno | last post by:
If I want to have a list like this: where the first part of each tuple is a variable name and the second part is a label for the user to see, such as a form like this: First Name: ________...
8
by: ridgedale | last post by:
I wonder if anyone could explain how I pass the field values in my request form to the PHP processor page. My external javascript file is as follows: var sections = ; for (var i=0; i <...
7
by: EyeHawk | last post by:
Iím fairly new on ASP and Javascript programming, I have read as much as I can to develop my website in a user friendly manner. Iím using javascript to pass some values in a Form, but is no working,...
2
by: ems9tech | last post by:
I can't get this count to return a number without an empty quote at the end ( " ) or getting NaN. Does anyone know why? I've searched and don't see any other postings on this issue. I'm using VS...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.