Including php in html

This is a discussion on "Including php in html" within the PHP Forum section. This forum, and the thread "Including php in html are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jan 21st, 2006, 18:02
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Including php in html

Hi,
I have a simple counter file written in php (just increments a value stored in a text file) when parsed all it displays is '35' or whatever the visitor number is.

I want to include this into a html homepage (I don't really want to change index.htm to index.php) so im wondering if i could use some html/javascript that would run counter.php so i see the output.

Something like this
<br>You are visitor number <b>(Code_for_including_counter.php)</b> Welcome</br>

Is this possible as I can't find a way to do it though i don't see why not. I suppose it would be possible using an iframe but i didnt want to do that either
Reply With Quote

  #2 (permalink)  
Old Jan 21st, 2006, 20:45
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Including php in html

I use

Code: Select all
AddType application/x-httpd-php .html
in a file called .htaccess in my home directory. This means that all .html files are in fact treated as PHP - which is no problem because PHP is an extension of HTML. If you do your own web server admin, you can configure it to allow you to use our method. If you buy space from an ISP, they might (or might not) let you do what I've suggested.
Reply With Quote
  #3 (permalink)  
Old Jan 21st, 2006, 20:59
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Including php in html

Hi, no they wouldnt let me do that,
I found that using this
HTML: Select all
<script url="./counter.php"></script>
accesses the script and increments the file by 1, however it doesn't output the number.

i.e.
<br>Number of visitors since January: <script url"./counter.php"></script>
doesn't output the number (I have the echo statement so it outputs the number if i just run counter.php as normal) but nothing when it runs from the html

Last edited by djme; Jan 21st, 2006 at 22:49.
Reply With Quote
  #4 (permalink)  
Old Jan 21st, 2006, 23:06
Junior Member
Join Date: Jan 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Including php in html

then create index.php and use that. for your index.html file, if you are worried about people having it bookmarked or whatever, do a redirect to your php file.
Reply With Quote
  #5 (permalink)  
Old Jan 21st, 2006, 23:12
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Including php in html

yeh but i didnt really want to do that if theres another way to do it - it seems pointless for such little code
Reply With Quote
  #6 (permalink)  
Old Jan 22nd, 2006, 21:11
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Including php in html

I just thought as im accessing the php and its carry out its task, all i need to do is import the data from the text file
Reply With Quote
  #7 (permalink)  
Old Jan 24th, 2006, 22:06
Junior Member
Join Date: Jan 2006
Age: 25
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Including php in html

Hey man you can do it actually! And you can do it quite easily. This little article has helped me do things sort of what your asking for many times. Its a minature implimentation of the AJAX, but without all the bells and whistles. You can run php scripts on the fly by accessing them through js.

http://www.devshed.com/c/a/PHP/PHP-a...Your-Resources
Reply With Quote
  #8 (permalink)  
Old Jan 28th, 2006, 07:37
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Including php in html

I'm assuming you are familiar with JavaScript, what you could make your counter.php into a JavaScript file, where it puts the number of visitors into a variable, include the script in the header of your html file, then call the variable with a short JavaScript. It should be really easy.
Reply With Quote
  #9 (permalink)  
Old Jan 28th, 2006, 12:25
Reputable Member
Join Date: Nov 2005
Posts: 127
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Including php in html

Cheers for that rprocter and pheonix, il try those out.
Reply With Quote
Reply

Tags
including, php, html

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Including a File Corey Bryant ASP.NET Forum 8 Mar 12th, 2008 03:27
including inside a function CloudedVision PHP Forum 2 Feb 11th, 2008 00:13
Webpage calender including clock satimis Web Page Design 0 Dec 28th, 2007 05:25
3 CSS Issues, including a float problem in IE6 TheoUK Web Page Design 1 Jul 3rd, 2007 23:56


All times are GMT. The time now is 11:44.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43