By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

Simple PHP counter without using echo

P: n/a

I have found dozen of useful PHP counters on the web. However, nobody
is working for my web pages, since administrator does not want to
enable the possibility that PHP could be called from HTML. (i.e.
"Addhandler application/x-httpd-php .html .php" in .htaccess). He
says it is a security problem.

Is it possible to make a PHP counter WITHOUT using echo command?

Thanks for your suggestions,

Marko
Jun 27 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Pygmalion wrote:
I have found dozen of useful PHP counters on the web. However, nobody
is working for my web pages, since administrator does not want to
enable the possibility that PHP could be called from HTML. (i.e.
"Addhandler application/x-httpd-php .html .php" in .htaccess). He
says it is a security problem.
Well, a security problem I doubt, but it is a bad idea to parse .html
files for PHP, search the group archives.
Is it possible to make a PHP counter WITHOUT using echo command?
The echo isn't the problem, the actually running of PHP is. As no PHP is
enabled in .html documents, it cannot increase a counter.

You can periodically parse an access log of apache instead (which will
show a delay in counter until parsed), and create an image (possibly
with the GD extension) on the fly with PHP, which you can insert into
your HTML document. Possibly you could also increase the counter on a
request for the image instead of parsing access logs, this would be less
reliable then access logs, however, I have never seen a counter where it
was of major importance to be reliable, normally they're just optional
candy, and disregarded by any visitor except the owner of the site (in
which case just parsing your access log is often already done by the
hosting company for your benefit).
--
Rik Wasmus
....spamrun finished
Jun 27 '08 #2

P: n/a
On Jun 3, 3:30 pm, Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
Pygmalion wrote:
I have found dozen of useful PHP counters on the web. However, nobody
is working for my web pages, since administrator does not want to
enable the possibility that PHP could be called from HTML. (i.e.
"Addhandler application/x-httpd-php .html .php" in .htaccess). He
says it is a security problem.

Well, a security problem I doubt, but it is a bad idea to parse .html
files for PHP, search the group archives.
Is it possible to make a PHP counter WITHOUT using echo command?

The echo isn't the problem, the actually running of PHP is. As no PHP is
enabled in .html documents, it cannot increase a counter.

You can periodically parse an access log of apache instead (which will
show a delay in counter until parsed), and create an image (possibly
with the GD extension) on the fly with PHP, which you can insert into
your HTML document. Possibly you could also increase the counter on a
request for the image instead of parsing access logs, this would be less
reliable then access logs, however, I have never seen a counter where it
was of major importance to be reliable, normally they're just optional
candy, and disregarded by any visitor except the owner of the site (in
which case just parsing your access log is often already done by the
hosting company for your benefit).
--
Rik Wasmus
...spamrun finished
Thanks for the answer. So apart from being a bad idea to use counters
at all, and calling PHP from HTML ... is there another possibility
(e.g. without using PHP) to make a simple counter? GD extension is
out of question, too, they refuse to install it.

Marko.
Jun 27 '08 #3

P: n/a
Pygmalion wrote:
On Jun 3, 3:30 pm, Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
>Pygmalion wrote:
>>I have found dozen of useful PHP counters on the web. However, nobody
is working for my web pages, since administrator does not want to
enable the possibility that PHP could be called from HTML. (i.e.
"Addhandler application/x-httpd-php .html .php" in .htaccess). He
says it is a security problem.
Well, a security problem I doubt, but it is a bad idea to parse .html
files for PHP, search the group archives.
>>Is it possible to make a PHP counter WITHOUT using echo command?
The echo isn't the problem, the actually running of PHP is. As no PHP is
enabled in .html documents, it cannot increase a counter.

You can periodically parse an access log of apache instead (which will
show a delay in counter until parsed), and create an image (possibly
with the GD extension) on the fly with PHP, which you can insert into
your HTML document. Possibly you could also increase the counter on a
request for the image instead of parsing access logs, this would be less
reliable then access logs, however, I have never seen a counter where it
was of major importance to be reliable, normally they're just optional
candy, and disregarded by any visitor except the owner of the site (in
which case just parsing your access log is often already done by the
hosting company for your benefit).

Thanks for the answer. So apart from being a bad idea to use counters
at all, and calling PHP from HTML ... is there another possibility
(e.g. without using PHP) to make a simple counter? GD extension is
out of question, too, they refuse to install it.
Python, Perl, Java, take your pick. You just need _something_ running
server sided, something has to hold a current count, and something has
to increment it. If you don't mind having only a counter for people with
only javascript you can just fetch a value with that and display it as
text, so then there's no need for GD.
--
Rik Wasmus
....spamrun finished
Jun 27 '08 #4

P: n/a
On Tue, 3 Jun 2008 06:44:26 -0700 (PDT), Pygmalion wrote:
Thanks for the answer. So apart from being a bad idea to use counters
at all, and calling PHP from HTML ... is there another possibility
(e.g. without using PHP) to make a simple counter? GD extension is
out of question, too, they refuse to install it.
Change your pages to .php extensions so that the php parse is called for
the ones that have php in them.

--
75. I will instruct my Legions of Terror to attack the hero en masse, instead
of standing around waiting while members break off and attack one or two
at a time.
--Peter Anspach's list of things to do as an Evil Overlord
Jun 27 '08 #5

P: n/a
Pygmalion schreef:
Thanks for the answer. So apart from being a bad idea to use counters
at all, and calling PHP from HTML ... is there another possibility
(e.g. without using PHP) to make a simple counter? GD extension is
out of question, too, they refuse to install it.
If you want to keep the .html extenstion, you can also change your
counter php file to produce JS compliant output. Afterwards, you can
include the file with a regular script tag.
JW
Jun 27 '08 #6

P: n/a
On Jun 3, 3:58 pm, Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
Pygmalion wrote:
On Jun 3, 3:30 pm, Rik Wasmus <luiheidsgoe...@hotmail.comwrote:
Pygmalion wrote:
I have found dozen of useful PHP counters on the web. However, nobody
is working for my web pages, since administrator does not want to
enable the possibility that PHP could be called from HTML. (i.e.
"Addhandler application/x-httpd-php .html .php" in .htaccess). He
says it is a security problem.
Well, a security problem I doubt, but it is a bad idea to parse .html
files for PHP, search the group archives.
>Is it possible to make a PHP counter WITHOUT using echo command?
The echo isn't the problem, the actually running of PHP is. As no PHP is
enabled in .html documents, it cannot increase a counter.
You can periodically parse an access log of apache instead (which will
show a delay in counter until parsed), and create an image (possibly
with the GD extension) on the fly with PHP, which you can insert into
your HTML document. Possibly you could also increase the counter on a
request for the image instead of parsing access logs, this would be less
reliable then access logs, however, I have never seen a counter where it
was of major importance to be reliable, normally they're just optional
candy, and disregarded by any visitor except the owner of the site (in
which case just parsing your access log is often already done by the
hosting company for your benefit).
Thanks for the answer. So apart from being a bad idea to use counters
at all, and calling PHP from HTML ... is there another possibility
(e.g. without using PHP) to make a simple counter? GD extension is
out of question, too, they refuse to install it.

Python, Perl, Java, take your pick. You just need _something_ running
server sided, something has to hold a current count, and something has
to increment it. If you don't mind having only a counter for people with
only javascript you can just fetch a value with that and display it as
text, so then there's no need for GD.
--
Rik Wasmus
...spamrun finished
What I did was that I am still calling PHP via <imgcommand, but
display value through javascript <script>document.write(name)</script>
command. As far as I know it would be impossible to open and write
file using Javascript. Is that correct?
Jun 27 '08 #7

P: n/a
On Jun 4, 10:39 am, Janwillem Borleffs <j...@jwscripts.comwrote:
Pygmalion schreef:
Thanks for the answer. So apart from being a bad idea to use counters
at all, and calling PHP from HTML ... is there another possibility
(e.g. without using PHP) to make a simple counter? GD extension is
out of question, too, they refuse to install it.

If you want to keep the .html extenstion, you can also change your
counter php file to produce JS compliant output. Afterwards, you can
include the file with a regular script tag.

JW
Great, that is exactly what I came across independently! The question
remains, do I still have to make a dummy PHP script call via <img>
command, or is there any more elegant way.
Jun 27 '08 #8

P: n/a
Pygmalion escribió:
I have found dozen of useful PHP counters on the web. However, nobody
is working for my web pages, since administrator does not want to
enable the possibility that PHP could be called from HTML. (i.e.
"Addhandler application/x-httpd-php .html .php" in .htaccess). He
says it is a security problem.

Is it possible to make a PHP counter WITHOUT using echo command?
If your question is "Can I execute PHP without a PHP interpreter", the
answers is obvious.

If you can actually execute PHP but you're restricted to files with
*.php extension, you can create a PHP script with the counter and link
it from the plain HTML. Typical options:

- An <iframethat points to the script, which returns a complete HTML
document.
- An <imgtag that points to the script, which returns a picture.
- A <scripttag that points to the script, which returns JavaScript
code; e.g. document.write("<p>You're visitor #987</p>")
- AJAX
P.S. I agree that parsing PHP in files with *.html extension is a
security risk (and not, as you may be tempted to think, a mere
performance issue); everybody knows that files with such file names are
way easier to hack.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #9

P: n/a
Álvaro G. Vicario wrote:
Pygmalion escribió:
>I have found dozen of useful PHP counters on the web. However, nobody
is working for my web pages, since administrator does not want to
enable the possibility that PHP could be called from HTML. (i.e.
"Addhandler application/x-httpd-php .html .php" in .htaccess). He
says it is a security problem.

Is it possible to make a PHP counter WITHOUT using echo command?

If your question is "Can I execute PHP without a PHP interpreter", the
answers is obvious.

If you can actually execute PHP but you're restricted to files with
*.php extension, you can create a PHP script with the counter and link
it from the plain HTML. Typical options:

- An <iframethat points to the script, which returns a complete HTML
document.
- An <imgtag that points to the script, which returns a picture.
- A <scripttag that points to the script, which returns JavaScript
code; e.g. document.write("<p>You're visitor #987</p>")
- AJAX
P.S. I agree that parsing PHP in files with *.html extension is a
security risk (and not, as you may be tempted to think, a mere
performance issue); everybody knows that files with such file names are
way easier to hack.
What "everybody knows" is not always correct. .html files parsed as php
are neither easier nor harder to hack than .php files. It's just a file
extension.

But it can be a significant performance hit.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.