By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,037 Members | 2,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,037 IT Pros & Developers. It's quick & easy.

How to Include PHP script in shtml file ???

P: n/a
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
Oct 27 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Lee
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.

Oct 27 '05 #2

P: n/a

"Lee" <RE**************@cox.net> skrev i en meddelelse
news:dj*********@drn.newsguy.com...
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.
Oct 27 '05 #3

P: n/a
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.
Oct 27 '05 #4

P: n/a

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

Oct 27 '05 #5

P: n/a
EnjoyNews said the following on 10/27/2005 10:47 AM:
"Lee" <RE**************@cox.net> skrev i en meddelelse
news:dj*********@drn.newsguy.com...
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
Oct 27 '05 #6

P: n/a

"Randy Webb" <Hi************@aol.com> skrev i en meddelelse
news:U7********************@comcast.com...
EnjoyNews said the following on 10/27/2005 10:47 AM:
"Lee" <RE**************@cox.net> skrev i en meddelelse
news:dj*********@drn.newsguy.com...
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..
Oct 27 '05 #7

P: n/a

"Michael Winter" <m.******@blueyonder.co.uk> skrev i en meddelelse
news:n_*******************@text.news.blueyonder.co .uk...
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. ??
Oct 27 '05 #8

P: n/a
EnjoyNews said the following on 10/27/2005 6:32 PM:
"Randy Webb" <Hi************@aol.com> skrev i en meddelelse
news:U7********************@comcast.com...
EnjoyNews said the following on 10/27/2005 10:47 AM:

"Lee" <RE**************@cox.net> skrev i en meddelelse
news:dj*********@drn.newsguy.com...
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
Oct 27 '05 #9

P: n/a

"Randy Webb" <Hi************@aol.com> skrev i en meddelelse
news:M8********************@comcast.com...
EnjoyNews said the following on 10/27/2005 6:32 PM:
"Randy Webb" <Hi************@aol.com> skrev i en meddelelse
news:U7********************@comcast.com...
EnjoyNews said the following on 10/27/2005 10:47 AM:
"Lee" <RE**************@cox.net> skrev i en meddelelse
news:dj*********@drn.newsguy.com...
>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 :o))

Michael
Oct 28 '05 #10

P: n/a
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.
Oct 28 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.