![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Apr 2006
Posts: 136
Rep Power: 0
![]() |
PHP Counter Script
I just got started with PHP and I am loving it. I have made a PHP script where it counts the number of users entering a web page for a web site. Now, I would like to call the script so that the counter get updates. I stored the contents in a file "count.txt" and have set the perimission to "777". ow for some reason, it shows the PHP source in the web page.
I called the script "counter.php". I tried putting [PHP] <?php include("counter.php"); ?> [/PHP] in the <head> tag and the below the <body> tag and all over the webpage. The source still shows. Here is the PHP script source [PHP] $file = "count.txt"; if (is_writable($file) { $file_contents = file_get_contents($file); if (!empty($file_contents)) { $new_content = $file_contents + 1; } else { $new_content = 1; } $file_handle = fopen($file, "w+"); $write = fwrite($file_handle, $new_content); fclosoe($file_handle ); if(!$write) { echo("Error updaing counter"); } else { echo("Counter Updated!"); } } else { $file2 = "error.txt"; $file_handle = fopen($file2, "w+"); $today = date("n:j:Y"); $messages = "Unable to date counter" $write = fwrite($file_handle, $messages); fclosoe($file_handle ); } [/PHP] How can I call the script without having to actually see the source within my web page. I want to see "Counter Updated" instead of the source. |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|