Results 1 to 22 of 22

Thread: PHP in .htm files

  1. #1

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485

    PHP in .htm files

    hi guys, is there a way to call php functions wihtin a .htm file, for example

    let's say i have a script which checks for a cookie for user preferences. and a seperate .htm file which uses these information, how is it achieved?
    me.life = VB

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    Does it have to be a .htm file?

  3. #3

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    er.. yeah thats the whole problem
    me.life = VB

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    No, you cannot have PHP in an .htm file.

    A .php file is parsed on the server, and all output is sent to the browser.

    A .htm file is sent to the browser as output without any parsing done. Any javascript, etc is done on the client itself.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    some sort of a redirection maybe.. are u 100% positive.. isnt it possible to call the external php file and ge the output.. and like..

    img src = img_rand.php

    and img_rand would retrive the image name.. i have seen this done somewhere....
    me.life = VB

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by deane034
    some sort of a redirection maybe.. are u 100% positive.. isnt it possible to call the external php file and ge the output.. and like..

    img src = img_rand.php

    and img_rand would retrive the image name.. i have seen this done somewhere....
    If you can do that, why can't you just use a .php file? What's your reason for needing a .htm file?

    And I'm 100% positive that you need to have PHP parsed on the server, and .htm files are most likely just sent directly to the client as output without being parsed for PHP.

    I'd be willing to bet...well, an empty wallet on it. Because I'm broke. But if I had money...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    you could try something like <!--#exec cgi="yourscript.php"-->

  8. #8
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    Originally posted by deane034
    img src = img_rand.php
    [/B]
    that does work if you only want to change the item being called, maybe you could dfo something like this

    phppage.php
    PHP Code:
    print 'document.write "'$_REQUEST['cookiename'] . '"'
    htmlpage.htm
    Code:
    <script language="javascript" src="phppage.php"></script>

  9. #9

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    coz this ppl i am buildin the scripts.. hate PHP.. they want.. a .htm extention.. god knows why.. i have to give them reasons why it isnt possible..
    me.life = VB

  10. #10
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    just found this, put it in the .htaccess file
    Code:
    AddType text/x-server-parsed-html .html
    it works for shtml files so maybe it could be changed for php files?

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by john tindell
    maybe you could dfo something like this

    phppage.php
    PHP Code:
    print 'document.write "'$_REQUEST['cookiename'] . '"'
    htmlpage.htm
    Code:
    <script language="javascript" src="phppage.php"></script>
    That wont work. The server will think it's a javascript file and send it to the client so that it can be parsed as so. It will not be parsed as PHP on the server.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    hi thanks for the replies, i think what i saw was something similar to the java script method Jogn posted earlier.. i am real new to scripting.. so help out guys...

    i tried the way jogn suggested. and i ddint somehow get the thing working. tyhis is the code i used,

    Code:
    test.htm
    
    <script language="javascript" 
    src="test.php"
    </script>
    
    trst.php
    
    <?php 
    
    print("document.write(\"deane034\") ");
    ?>
    thanks
    me.life = VB

  13. #13

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    ok didnt see hobo's post.. so does that mean there is no solution?
    me.life = VB

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I already said that it wouldn't work...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by deane034
    ok didnt see hobo's post.. so does that mean there is no solution?
    Personally, I'd go talk to the people you're working for and slap the ignorance out of them. Explain to them what a great technology PHP is and that even using .htm files is outdated.

    Ask them if they want to be stuck in the early 90s forever.

    Otherwise, I believe you can manipulate cookies with javascript. I'm not sure about it, though, but I vaguely remember hearing about it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  16. #16
    You can force the server (*nix server) to parse any file you want with .htaccess. Download the attatched file, extract the .htaccess file and upload it to the dirctory you want this forcing to take action in. The .htaccess file contains the following code, if you want to make it yourself:

    Code:
    AddType application/x-httpd-php .htm
    Now the server see's the htaccess file and knows that you want it to recognize the .htm files as PHP and force parse it.

    Though there's no point in trying this if you host doesn't even support PHP!

    So just upload the .htaccess file and stick in your PHP. No need to put <script> or anything in.

    And if your on a Windows server, then your SOL.

  17. #17
    Forgot to attache it
    Attached Files Attached Files

  18. #18
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    Originally posted by Chroder
    And if your on a Windows server, then your SOL.
    whats that?

  19. #19
    Sh*t Outta Luck

  20. #20
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    lol

  21. #21

    Thread Starter
    Hyperactive Member deane034's Avatar
    Join Date
    May 2001
    Location
    Sri Lanka
    Posts
    485
    thanks ppl..

    hey chroder is there way to set the .htaccess file so that it only parses only some given list of htm files... coz they now they only want theere home page index.htm to be in index.htm.. so that the browser will display ww.something.com instead of something.com/index.php ...
    me.life = VB

  22. #22
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Why does it display an index.php?
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width