Hi everybody!
I have a simple question: I have a HTML file (let's call it index.html). I want to put a php counter in this page (not shown on the page, only for my information). I don't understand very well the PHP philosophy... because I know perfectly to create a php file, containing a counter. But how can I launch this script automaticaly when the index.html page is accesed?
Thank you all and have a nice day.
Php simple counter
Moderator: General Moderators
change "index.html" to "index.php". And add the following code
And create a new file called "counter.inc" in the same folder as "index.php". Change the permission to "777".
Code: Select all
<?php
$fh = fopen("counter.inc","a+");
$count = fread($fh,filesize($fh));
$count++;
fwrite($fh,$count);
fclose($fh);
?>Mention note ...
Thanx Takuma. I knew this solution (changing the index.html into index.php and so on...)
The problem is that I want to keep my index.html file and to call the 'counter.inc' from inside it. Is there any posibility? Like an automatically launched FORM (without the SUBMIT button) with the php script as the action. Is it a possibility? Can you include a FORM into a a.html file to launch automatically a php file, withou any SUBMIT button?
Thank you all for you time.
The problem is that I want to keep my index.html file and to call the 'counter.inc' from inside it. Is there any posibility? Like an automatically launched FORM (without the SUBMIT button) with the php script as the action. Is it a possibility? Can you include a FORM into a a.html file to launch automatically a php file, withou any SUBMIT button?
Thank you all for you time.
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
Hi,
See the code below, which does the automatic FORM submit to .php file:
The document.frm.submit() can be written in the onLoad itself also. But in case if you want to do any more processing, you can do it in the submitFrm(). The <FORM> can contain any hidden variables also.
Regards,
See the code below, which does the automatic FORM submit to .php file:
Code: Select all
<HTML>
<HEAD>
<SCRIPT type="text/javascript">
function submitFrm()
{
document.frm.submit();
}
</SCRIPT>
</HEAD>
<BODY onLoad="submitFrm();">
<FORM name=frm action=counter.php>
</FORM>
</BODY>
</HTML>Regards,