Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. first code
  2.  
  3.  
  4. <?php
  5.  
  6. $filename = 'click_count.txt';
  7. $handle = fopen($filename, 'r');
  8. $hits = trim(fgets($handle)) + 1;
  9. fclose($handle);
  10.  
  11. $handle = fopen($filename, 'w');
  12. fwrite($handle, $hits);
  13. fclose($handle);
  14.  
  15. // Uncomment the next line (remove //) to display the number of hits on your page.
  16. //echo $hits;
  17.  
  18. ?>
  19.  
  20.  
  21. second code
  22.  
  23. <?php
  24.  
  25. $click_value = '0.001'; //Amount in dollars that each click is worth
  26.  
  27. function increment_clicks()
  28. {
  29. //Get current click count
  30. $clicks = ((file_exists('click_count.txt')) ? file_get_contents('click_count.txt') : 0);
  31.  
  32. //Add current click to count
  33. $clicks++;
  34.  
  35. //Save new value to file
  36. $file = fopen('click_count.txt', 'w');
  37. fwrite($file, $clicks);
  38. fclose($file);
  39. }
  40.  
  41. function get_click_amount()
  42. {
  43. global $click_value;
  44.  
  45. //Get current click count
  46. $clicks = ((file_exists('click_count.txt')) ? file_get_contents('click_count.txt') : 0);
  47.  
  48. //Return value of all clicks based on $click_value, formatted to 2 decimal places
  49. return number_format($clicks * $click_value, 3);
  50. }
  51.  
  52. if (isset($_GET['sa']))
  53. {
  54. //Search button was clicked, increment count
  55. increment_clicks();
  56. }
  57.  
  58. $click_amount = get_click_amount();
  59. ?>
  60.  
  61.  
  62. can someone tell me why when the amount goes from $1.999 then next one goes back to $1.000 not $2.000 thanks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement