Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 7th, 2006, 10:50 PM   #1
Toro
Hobbyist Programmer
 
Toro's Avatar
 
Join Date: Apr 2006
Posts: 136
Rep Power: 0 Toro is an unknown quantity at this point
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.
Toro is offline   Reply With Quote
Old Jun 7th, 2006, 10:55 PM   #2
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 903
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Enclose the PHP script source (not just the include statement) in <?php ... ?> tags.
titaniumdecoy is offline   Reply With Quote
Old Jun 7th, 2006, 11:08 PM   #3
Toro
Hobbyist Programmer
 
Toro's Avatar
 
Join Date: Apr 2006
Posts: 136
Rep Power: 0 Toro is an unknown quantity at this point
thanks titaniumdecoy! I feel really dumb!
Toro is offline   Reply With Quote
Old Jun 8th, 2006, 1:01 AM   #4
splinter9x
Hobbyist Programmer
 
splinter9x's Avatar
 
Join Date: Jun 2006
Posts: 137
Rep Power: 0 splinter9x is an unknown quantity at this point
That might work lol...
__________________
Visit my Blog
I support WINDOWS...
splinter9x is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:57 AM.

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