Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   PHP Counter Script (http://www.programmingforums.org/showthread.php?t=10242)

Toro Jun 7th, 2006 9:50 PM

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.

titaniumdecoy Jun 7th, 2006 9:55 PM

Enclose the PHP script source (not just the include statement) in <?php ... ?> tags.

Toro Jun 7th, 2006 10:08 PM

thanks titaniumdecoy! I feel really dumb!

splinter9x Jun 8th, 2006 12:01 AM

That might work lol...


All times are GMT -5. The time now is 11:19 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC