FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Why is this happening ??





varun_dodla
I'm a novice to php. I needed a hit counter for my website and found a php module for it. When i call the script directly it execute but not on the test (html) page please help.


counter.php ( http://varunswebpages.com/counter/counter.php )

<?php
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>


counter.htm ( http://varunswebpages.com/counter/counter.htm )

<html>
<head><title>counter</title>
</head>
<body>
Visitor Number
<?php include("counter.php"); ?>
</body>
</html>

The script runs when called directly but not from the html page please help.
wumingsden
varun_dodla wrote:
I'm a novice to php. I needed a hit counter for my website and found a php module for it. When i call the script directly it execute but not on the test (html) page please help.


counter.php ( http://varunswebpages.com/counter/counter.php )

<?php
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
$hits[0] ++;
$fp = fopen($count_my_page , "w");
fputs($fp , "$hits[0]");
fclose($fp);
echo $hits[0];
?>


counter.htm ( http://varunswebpages.com/counter/counter.htm )

<html>
<head><title>counter</title>
</head>
<body>
Visitor Number
<?php include("counter.php"); ?>
</body>
</html>

The script runs when called directly but not from the html page please help.


to execute php, even with includes, the oage has to have a .php extension. Simple change it to *file_name*.php As i can see the original php file is called counter.php so you shouldn't rename counter.htm to counter.php.

To solve it rather change counter.htm to counters.php (notice its called "counters" not "counter"

or add your html code into the counter.php file
Rhysige
Just so you know HTML works in .php files all you need to do is make sure it has the normal tags and is not inside the <?php and ?> tags unless you are echoing it.
varun_dodla
Thanx a lot wumingsden. I tried that and it is woking now but I have one more small doubt. Now if I want to have this hit counter on all my webpages do I need to rename all to .php but then all the links have to be changed also i suppose. Is there any other way.
sonam
Quote:
Now if I want to have this hit counter on all my webpages do I need to rename all to .php but then all the links have to be changed also i suppose. Is there any other way.


I haven't my comp here and I cannot help you plenty but maybe you can to use <iframe>. Every time when some html page load counter.php in this <iframe> count one +, and display counter results in same <iframe>.

Sonam
DanielXP
Whats the point of that they both say 'Your Visitor Number is: __'
Related topics
10 Reasons why PC's crash
Why people hate Windows?
Does anyone know why this is happening?
Payroll tax holiday - why only now?
Why not unlock moderators now!
Why 2012 is the MOST anticipated year till date.
Why our life is like that...
why not install ZendOptimizer?
problem in sql and importing db.
Why not Adding .... this ...
why no hosting under .com
why I cannot use kf97.uni.cc domain admin help me!!
Why use IE?
That's Why
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.