How to Include PHP script in shtml file ???

Discussion in 'Javascript' started by EnjoyNews, Oct 27, 2005.

  1. EnjoyNews

    EnjoyNews Guest

    I have a php site I have an include line called "include 'Cookie.php';"

    In this Cookie.php file I have these codes.

    <?php
    $conn = mysql_connect("$db", "$user", "$pass");
    mysql_select_db("$db");

    //--------------------------------------------------------------------------
    -------------
    //COOKIE
    //--------------------------------------------------------------------------
    -------------
    $cookiename = 'TourCounter';
    if( isset( $_COOKIE[$cookiename] ) ){$user_id = $_COOKIE[$cookiename];}
    else {
    mysql_query ("INSERT INTO CountUser (Dato) VALUES (now())");
    $user_id = mysql_insert_id();
    setcookie( $cookiename, $user_id, time()+315360000);
    ;}?>


    This will set a cookie on the computer when people enters the site for the
    first time, and update my database.
    Now I can see how many new computers that see my site each day, and it works
    fine.


    BUT, now I have another site where all the pages are .shtml sites, and I
    have not been using any php scripting at all, though it is uploadet on a
    server where I can use php.

    But now I can't include the file, cause if I write <!--#include
    file="Cookie.php"--> it includes some php codes, but since the site is
    called .shtml it offcause can't execute the php script.

    But isn't there a way to do this anyway.
    Maybe by some javascript that executes the Cookie.php fil or something. ??
    The site has a lot a pages, and I would rather not rename them all to .php
    and the shtml include to php include on all the pages.

    I have a menu that is included on all the pages, so if it could be executed
    in the menu file, I will count all hits, nomatter what site people enters
    first.


    Hope someone have a good idea.

    best
    Michael
     
    EnjoyNews, Oct 27, 2005
    #1
    1. Advertising

  2. EnjoyNews

    Lee Guest

    EnjoyNews said:
    >
    >I have a php site I have an include line called "include 'Cookie.php';"
    >
    >In this Cookie.php file I have these codes.


    You seem to be asking a PHP question in a Javascript newsgroup.
    Asking in a more appropriate place will produce better answers.
     
    Lee, Oct 27, 2005
    #2
    1. Advertising

  3. EnjoyNews

    EnjoyNews Guest

    "Lee" <> skrev i en meddelelse
    news:...
    > EnjoyNews said:
    > >
    > >I have a php site I have an include line called "include 'Cookie.php';"
    > >
    > >In this Cookie.php file I have these codes.

    >
    > You seem to be asking a PHP question in a Javascript newsgroup.
    > Asking in a more appropriate place will produce better answers.
    >


    No I not asking a php question.
    The php script is working fine on my other site, which is coded in php.

    But now I need the php script to be executed from a .shtml site.
    So now I can't include the Cookie.php script, since it only works if the
    site is called .php

    So therefore I'm asking here if I somehow can execute a .php fil with
    jacvascript.
     
    EnjoyNews, Oct 27, 2005
    #3
  4. On 27/10/2005 15:47, EnjoyNews wrote:

    [snip]

    > But now I need the php script to be executed from a .shtml site.


    That still isn't a question for this group. That's a server
    configuration issue.

    What's a .shtml site, anyway?

    > So now I can't include the Cookie.php script, since it only works if the
    > site is called .php


    The extension used is really rather irrelevant. A server could send
    files that have the extension .cheese to PHP.

    If you want the server to pass a file through PHP, then either name that
    file in a way that will make the server do that (usually using an .php
    extension), or change the server configuration.

    [snip]

    Mike

    --
    Michael Winter
    Prefix subject with [News] before replying by e-mail.
     
    Michael Winter, Oct 27, 2005
    #4
  5. EnjoyNews wrote:

    > I have a php site I have an include line called "include 'Cookie.php';"
    >
    > In this Cookie.php file I have these codes.
    >
    > <?php
    > $conn = mysql_connect("$db", "$user", "$pass");
    > mysql_select_db("$db");
    >
    > //--------------------------------------------------------------------------
    > -------------
    > //COOKIE
    > //--------------------------------------------------------------------------
    > -------------
    > $cookiename = 'TourCounter';
    > if( isset( $_COOKIE[$cookiename] ) ){$user_id = $_COOKIE[$cookiename];}
    > else {
    > mysql_query ("INSERT INTO CountUser (Dato) VALUES (now())");
    > $user_id = mysql_insert_id();
    > setcookie( $cookiename, $user_id, time()+315360000);
    > ;}?>
    >
    >
    > This will set a cookie on the computer when people enters the site for the
    > first time, and update my database.
    > Now I can see how many new computers that see my site each day, and it works
    > fine.
    >
    >
    > BUT, now I have another site where all the pages are .shtml sites, and I
    > have not been using any php scripting at all, though it is uploadet on a
    > server where I can use php.
    >
    > But now I can't include the file, cause if I write <!--#include
    > file="Cookie.php"--> it includes some php codes, but since the site is
    > called .shtml it offcause can't execute the php script.
    >
    > But isn't there a way to do this anyway.
    > Maybe by some javascript that executes the Cookie.php fil or something. ??
    > The site has a lot a pages, and I would rather not rename them all to .php
    > and the shtml include to php include on all the pages.
    >
    > I have a menu that is included on all the pages, so if it could be executed
    > in the menu file, I will count all hits, nomatter what site people enters
    > first.
    >
    >
    > Hope someone have a good idea.
    >
    > best
    > Michael


    One option to explore may be to use some kind of remote scripting
    solution, such as HTTPRequest. There is a lot of information to be
    found on the HTTPRequest object.

    I.e. when your menu file is loaded and run, you make an HTTPRequest to
    "Cookie.php".

    E.g. something like:-

    var oHTTP=new ActiveXObject("Microsoft.XMLHttp");
    oHTTP.open("GET","Cookie.php", false);
    oHTTP.send(null);

    This is very rough. Have a look at the SARISSA library for
    cross-browser versions. It will only work on later browsers, so even if
    it works, it may not a complete solution for you.

    Julian
     
    Julian Turner, Oct 27, 2005
    #5
  6. EnjoyNews

    Randy Webb Guest

    EnjoyNews said the following on 10/27/2005 10:47 AM:

    > "Lee" <> skrev i en meddelelse
    > news:...
    >
    >>EnjoyNews said:
    >>
    >>>I have a php site I have an include line called "include 'Cookie.php';"
    >>>
    >>>In this Cookie.php file I have these codes.

    >>
    >>You seem to be asking a PHP question in a Javascript newsgroup.
    >>Asking in a more appropriate place will produce better answers.
    >>

    >
    >
    > No I not asking a php question.
    > The php script is working fine on my other site, which is coded in php.
    >
    > But now I need the php script to be executed from a .shtml site.
    > So now I can't include the Cookie.php script, since it only works if the
    > site is called .php
    >
    > So therefore I'm asking here if I somehow can execute a .php fil with
    > jacvascript.


    How about with plain HTML?

    <img src="phpFileToExecute.php" width="0" height="0" style="visibility:
    hidden">

    Or, you could configure your server to parse .shtml files through PHP.

    Either way, it has nothing to do with javascript.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Oct 27, 2005
    #6
  7. EnjoyNews

    EnjoyNews Guest

    "Randy Webb" <> skrev i en meddelelse
    news:...
    > EnjoyNews said the following on 10/27/2005 10:47 AM:
    >
    > > "Lee" <> skrev i en meddelelse
    > > news:...
    > >
    > >>EnjoyNews said:
    > >>
    > >>>I have a php site I have an include line called "include 'Cookie.php';"
    > >>>
    > >>>In this Cookie.php file I have these codes.
    > >>
    > >>You seem to be asking a PHP question in a Javascript newsgroup.
    > >>Asking in a more appropriate place will produce better answers.
    > >>

    > >
    > >

    >
    > How about with plain HTML?


    Yes it's simple html. I just told that the site was called shtml, cause
    maybe that has something to do with how the javascript should look like.
    But yes it is a standard html site.


    >
    > <img src="phpFileToExecute.php" width="0" height="0" style="visibility:
    > hidden">


    Is this really possible.... ???
    I thought the <img src command could only be used to view images. ???

    But if this is possible, it was exactly what I was looking for. A way to
    open a file (in this case a .php file) without opening another browser
    window or something like that...


    >
    > Or, you could configure your server to parse .shtml files through PHP.


    Is this something I do myself, or do I have to ask my webhost about this ??


    >
    > Either way, it has nothing to do with javascript.


    I know this has nothing to do with javascripting, but I didn't know how to
    do it in html, so I thought maybe it could be done with javascripting, and
    that's why I asked here..
     
    EnjoyNews, Oct 27, 2005
    #7
  8. EnjoyNews

    EnjoyNews Guest

    "Michael Winter" <> skrev i en meddelelse
    news:n_58f.138762$...
    > On 27/10/2005 15:47, EnjoyNews wrote:
    >
    > [snip]
    >
    > > But now I need the php script to be executed from a .shtml site.

    >
    > That still isn't a question for this group. That's a server
    > configuration issue.


    I thought maybe some javascript in my .html file could execute another file,
    in this case a .php file.
    That's why I asked here.


    >
    > What's a .shtml site, anyway?


    it's a .html file that uses serverside commands like "include file"
    It's not important in this case if it's a html or shtml file, that info was
    just to inform which file the javascripting should be placed in, if it was
    possible.


    >
    > > So now I can't include the Cookie.php script, since it only works if the
    > > site is called .php

    >
    > The extension used is really rather irrelevant. A server could send
    > files that have the extension .cheese to PHP.
    >
    > If you want the server to pass a file through PHP, then either name that
    > file in a way that will make the server do that (usually using an .php
    > extension), or change the server configuration.


    It's rather complicated to rename the files from .shtml to .php, since all
    the serverside commands used in the files, does not work in an .php file.
    That's why I'm not changing the extension.

    But how do I get the server to pass .shtml file through PHP. ??
     
    EnjoyNews, Oct 27, 2005
    #8
  9. EnjoyNews

    Randy Webb Guest

    EnjoyNews said the following on 10/27/2005 6:32 PM:
    > "Randy Webb" <> skrev i en meddelelse
    > news:...
    >
    >>EnjoyNews said the following on 10/27/2005 10:47 AM:
    >>
    >>
    >>>"Lee" <> skrev i en meddelelse
    >>>news:...
    >>>
    >>>
    >>>>EnjoyNews said:
    >>>>
    >>>>
    >>>>>I have a php site I have an include line called "include 'Cookie.php';"
    >>>>>
    >>>>>In this Cookie.php file I have these codes.
    >>>>
    >>>>You seem to be asking a PHP question in a Javascript newsgroup.
    >>>>Asking in a more appropriate place will produce better answers.
    >>>>
    >>>
    >>>

    >>How about with plain HTML?

    >
    >
    > Yes it's simple html. I just told that the site was called shtml, cause
    > maybe that has something to do with how the javascript should look like.
    > But yes it is a standard html site.
    >
    >
    >
    >><img src="phpFileToExecute.php" width="0" height="0" style="visibility:
    >>hidden">

    >
    >
    > Is this really possible.... ???


    Yes, it is really possible. It is the basis of most page hit counters.

    > I thought the <img src command could only be used to view images. ???


    Test it and see :)

    > But if this is possible, it was exactly what I was looking for. A way to
    > open a file (in this case a .php file) without opening another browser
    > window or something like that...


    Yes, very possible.

    >
    >
    >>Or, you could configure your server to parse .shtml files through PHP.

    >
    >
    > Is this something I do myself, or do I have to ask my webhost about this ??


    Your webhost would have to do it.

    >
    >
    >>Either way, it has nothing to do with javascript.

    >
    >
    > I know this has nothing to do with javascripting, but I didn't know how to
    > do it in html, so I thought maybe it could be done with javascripting, and
    > that's why I asked here..


    It can be done with plain HTML.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Oct 27, 2005
    #9
  10. EnjoyNews

    EnjoyNews Guest

    "Randy Webb" <> skrev i en meddelelse
    news:...
    > EnjoyNews said the following on 10/27/2005 6:32 PM:
    > > "Randy Webb" <> skrev i en meddelelse
    > > news:...
    > >
    > >>EnjoyNews said the following on 10/27/2005 10:47 AM:
    > >>
    > >>
    > >>>"Lee" <> skrev i en meddelelse
    > >>>news:...
    > >>>
    > >>>
    > >>>>EnjoyNews said:
    > >>>>
    > >>>>
    > >>>>>I have a php site I have an include line called "include

    'Cookie.php';"
    > >>>>>
    > >>>>>In this Cookie.php file I have these codes.
    > >>>>
    > >>>>You seem to be asking a PHP question in a Javascript newsgroup.
    > >>>>Asking in a more appropriate place will produce better answers.
    > >>>>
    > >>>
    > >>>
    > >>How about with plain HTML?

    > >
    > >
    > > Yes it's simple html. I just told that the site was called shtml, cause
    > > maybe that has something to do with how the javascript should look like.
    > > But yes it is a standard html site.
    > >
    > >
    > >
    > >><img src="phpFileToExecute.php" width="0" height="0" style="visibility:
    > >>hidden">

    > >
    > >
    > > Is this really possible.... ???

    >
    > Yes, it is really possible. It is the basis of most page hit counters.
    >
    > > I thought the <img src command could only be used to view images. ???

    >
    > Test it and see :)



    I have done what you said, and it works perfect.
    So now I can upload my folder called Counter, where the Cookie.php file is
    in, and a php site to view the result from my MySQL database.
    Then all I have to do is put the line
    <img src="Counter/Cookie.php" width="0" height="0">
    on a site that is view all the time, like the menu.
    And then I can see how many new computer that have entered the site. The
    cookie is on each computer for 10 years, so if people doens't reinstall, it
    will only count one hits from each computer one time in 10 years.

    Thanks a lot for you help :eek:))

    Michael
     
    EnjoyNews, Oct 28, 2005
    #10
  11. On 27/10/2005 23:38, EnjoyNews wrote:

    [snip]

    > I thought maybe some javascript in my .html file could execute
    > another file, in this case a .php file. [...]


    It could, but it's not a good solution. One of the advantages of using
    the server is that you can reliably perform actions using it. Using a
    client-side script negates this reliability and, let's face it, the
    reason why you're looking for a quick way out is because you're not
    inclined to make the necessary effort to solve the problem properly.

    [Me:]
    >> What's a .shtml site, anyway?

    >
    > it's a .html file that uses serverside commands like "include file"


    I'm well aware of SSI. You missed my point, but it's not important.

    [snip]

    > It's rather complicated to rename the files from .shtml to .php,
    > since all the serverside commands used in the files, does not work in
    > an .php file.


    With your server configuration, yes. However, it strikes me as rather
    odd that you didn't forsee this issue.

    [snip]

    > But how do I get the server to pass .shtml file through PHP. ??


    I'm curious to know why it doesn't anyway. An SSI include element should
    pass a PHP script through the preprocessor. The URL for the virtual
    attribute value (typically preferred over file) can even include a query
    string that can be accessed as usual.

    If the server is configured with IncludesNOEXEC, rather than Includes,
    then an error will result because permission to execute the script was
    not granted, but you made no mention of that.

    Mike

    --
    Michael Winter
    Prefix subject with [News] before replying by e-mail.
     
    Michael Winter, Oct 28, 2005
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kenneth Baltrinic

    How to get VS IDE to recognize .shtml docs as html

    Kenneth Baltrinic, Nov 19, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    424
    Kenneth Baltrinic
    Nov 20, 2003
  2. Replies:
    4
    Views:
    1,324
  3. Andreas Bogenberger
    Replies:
    3
    Views:
    1,014
    Andreas Bogenberger
    Feb 22, 2008
  4. Rajive Narain
    Replies:
    0
    Views:
    2,097
    Rajive Narain
    Sep 18, 2009
  5. Miquel Oliete
    Replies:
    4
    Views:
    182
    Miquel Oliete
    Mar 7, 2008
Loading...

Share This Page