Welcome to HostingForumz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Including Files--PHP or Perl?

 
   Web Hosting Problem Solving Community! (Home) -> Webmaster RSS
Next:  ioncube (Tina, others?)  
Author Message
beelymagee

External


Since: May 11, 2004
Posts: 5



(Msg. 1) Posted: Mon Jun 21, 2004 2:55 am
Post subject: Including Files--PHP or Perl?
Archived from groups: alt>www>webmaster (more info?)

I'm trying to do something that I'm sure I don't understand all of the
options and ramifications. I would like to take a CSS code chunk of
navigation menus and not have to type it into every page on my site.
Instead I'd like to have a function in PHP or CGI/Perl known as INCLUDE
to have the file containing the chunk of CSS-HTML code dynamically
inserted into each web page as it is invoked. Do I understand this
correctly? Can this be done? or should I simply code each page and then
update all the pages when I want to make changes to the menus? (Not an
optimal solution.) I'm brand new to both languages.

Here's what I've found for PHP -- haven't gotten this to work:
<?php
include some_code.inc;
?>

Here's what I've found for CGI-Perl -- haven't gotten this to work:
<!--#include file="some_code.html"-->
or
<!--#include virtual="some_code.html"-->

Anybody done anything like this? I'd appreciate a few pointers, any and
all help.

-*-Bill
--

Windows has detected that your mouse has moved,
please wait while Windows reboots for your changes to take effect.

 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
venomx

External


Since: Jun 13, 2004
Posts: 1064



(Msg. 2) Posted: Mon Jun 21, 2004 7:06 am
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Bill M. wrote:
 > I'm trying to do something that I'm sure I don't understand all of the
 > options and ramifications. I would like to take a CSS code chunk of
 > navigation menus and not have to type it into every page on my site.
 > Instead I'd like to have a function in PHP or CGI/Perl known as
 > INCLUDE to have the file containing the chunk of CSS-HTML code
 > dynamically inserted into each web page as it is invoked. Do I
 > understand this correctly? Can this be done? or should I simply code
 > each page and then update all the pages when I want to make changes
 > to the menus? (Not an optimal solution.) I'm brand new to both
 > languages.
 >
 > Here's what I've found for PHP -- haven't gotten this to work:
 > <?php
 > include some_code.inc;
  >>
 >
 > Here's what I've found for CGI-Perl -- haven't gotten this to work:
 > <!--#include file="some_code.html"-->
 > or
 > <!--#include virtual="some_code.html"-->
 >
 > Anybody done anything like this? I'd appreciate a few pointers, any
 > and all help.
 >
 > -*-Bill

Here is what I use in my PHP pages
<? include("account_menu.php");?>

in the account_menu.php is plain HTML<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
tobyink

External


Since: Apr 25, 2004
Posts: 148



(Msg. 3) Posted: Mon Jun 21, 2004 11:14 am
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Bill M. wrote:

 > Instead I'd like to have a function in PHP or CGI/Perl known as INCLUDE
 > to have the file containing the chunk of CSS-HTML code dynamically
 > inserted into each web page as it is invoked. Do I understand this
 > correctly? Can this be done?

Yes, although your server will have to support it.

 > Here's what I've found for CGI-Perl -- haven't gotten this to work:
 > <!--#include file="some_code.html"-->
 > or
 > <!--#include virtual="some_code.html"-->

This is SSI, not Perl.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - <a style='text-decoration: underline;' href="http://www.goddamn.co.uk/tobyink/?page=132" target="_blank">http://www.goddamn.co.uk/tobyink/?page=132</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
mail6

External


Since: Feb 24, 2004
Posts: 58



(Msg. 4) Posted: Mon Jun 21, 2004 3:10 pm
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Bill M." <beelymagee.RemoveThis@cox.net> wrote in message
news:20040620235522.3925513d.beelymagee@cox.net...
<
 > Here's what I've found for PHP -- haven't gotten this to work:
 > <?php
 > include some_code.inc;
 > ?>

You need to make sure PHP is supported on your server. Also in most cases
the file the code is contained in will have to have a .php extension. The
extension of the file you are including is not important. However it's best
to keep it as .html (not .inc) for consistency. If you want the included
file to also have included files this needs to be .php extension too

Also make sure you use the correct syntax
e.g.
<?php
include("some_code.html");
?>



 > Here's what I've found for CGI-Perl -- haven't gotten this to work:
 > <!--#include file="some_code.html"-->
 > or
 > <!--#include virtual="some_code.html"-->
 >
 > Anybody done anything like this? I'd appreciate a few pointers, any and
 > all help.

That is Server Side Includes, it's nothing whatever to do with Perl.

Your code looks fine there. However just like PHP you have to make sure that
SSI is supported on your server. Plus again you often have to change the
extension of the page to .shtml or similar.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
user233

External


Since: Sep 26, 2003
Posts: 261



(Msg. 5) Posted: Mon Jun 21, 2004 4:19 pm
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Viper wrote:
 > Bill M. wrote:
  >>Here's what I've found for PHP -- haven't gotten this to work:
  >><?php
  >> include some_code.inc;
 >
 > Here is what I use in my PHP pages
 > <? include("account_menu.php");?>
 >
 > in the account_menu.php is plain HTML

If it's just plain HTML, you could also use readfile(),
<http://www.php.net/readfile>. This way the server won't waste valuable
nanoseconds trying to evaluate the specified file.


Matthias<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
venomx

External


Since: Jun 13, 2004
Posts: 1064



(Msg. 6) Posted: Mon Jun 21, 2004 4:19 pm
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Matthias Gutfeldt wrote:
 > Viper wrote:
  >> Bill M. wrote:
   >>> Here's what I've found for PHP -- haven't gotten this to work:
   >>> <?php
   >>> include some_code.inc;
  >>
  >> Here is what I use in my PHP pages
  >> <? include("account_menu.php");?>
  >>
  >> in the account_menu.php is plain HTML
 >
 > If it's just plain HTML, you could also use readfile(),
 > <http://www.php.net/readfile>. This way the server won't waste
 > valuable nanoseconds trying to evaluate the specified file.
 >
 >
 > Matthias

Well its a site that runs a script I bought and thats how they set it up.. I
do see a few <? inboxcount();?> in the file so its not all HTML as I
thought...<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
beelymagee

External


Since: May 11, 2004
Posts: 5



(Msg. 7) Posted: Mon Jun 21, 2004 6:54 pm
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Toby,

On Mon, 21 Jun 2004 08:14:02 +0100
Toby A Inkster <tobyink RemoveThis @goddamn.co.uk> wrote:

 > Bill M. wrote:
 >
  > > Here's what I've found for CGI-Perl -- haven't gotten this to work:
  > > <!--#include file="some_code.html"-->
  > > or
  > > <!--#include virtual="some_code.html"-->
 >
 > This is SSI, not Perl.

OK - thanks for the clarification. Aside from that, do you feel you have
a response about my issue posted?

-*-Bill<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
beelymagee

External


Since: May 11, 2004
Posts: 5



(Msg. 8) Posted: Mon Jun 21, 2004 7:29 pm
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Sun, 20 Jun 2004 23:55:22 -0700
"Bill M." <beelymagee.TakeThisOut@cox.net> wrote:

Here's some php code to see output. I'm using php 4.3.3 (from a php,
MySQL, Apache book CD.) I have Apache2 (not sure what sub-version it
is) and it's started via "apachectl start" I'm getting odd output from
this(see below):

<html>
<head>
<title>Testing INCLUDE command</title>
</head>
<body>
<p> Here's some text to show that this PHP file is working ...</p>
<?php
  echo "<BR />";
  echo "<BR />";
  echo "<h1>Here is some other text ECHOed from the PHP command
file</h1>";
  if (file_exists("navMenus.php")) {
   echo "<h3>The Navigation Menus file exists according to
PHP!</h3>"; }
  if (is_readable("navMenus.php")) {
   echo "<h3>An the Navigation Menus file is READable to
boot!</h3>"; }
?>

<? include("navMenus.php"); ?>

</body>
</html>

Here's the output (in Opera 7.51 Linux) from the above:

Here's some text to show that this PHP file is working ...
"; echo "
"; echo "
Here is some other text ECHOed from the PHP command file
if (file_exists("navMenus.php")) { echo "
The Navigation Menus file exists according to PHP!
"; } if (is_readable("navMenus.php")) { echo "
An the Navigation Menus file is READable to boot!
"; } ?>

I still don't get any output from the navMenus.php file - PHP sez the
file exists and is readable.

I changed the above ECHO commands to PRINT in the hope that it would
remove the "; echo " gibberish - no change. The HTML headers(<h1, h3>)
came out formatted as expected. I saw mention of the READFILE()
command (thanks, Mathias!) - I may play with that to see if that is a
better solution.

-*-Bill
--

Windows has detected that your mouse has moved,
please wait while Windows reboots for your changes to take effect.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
tobyink

External


Since: Apr 25, 2004
Posts: 148



(Msg. 9) Posted: Mon Jun 21, 2004 9:49 pm
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Mark Hewitt wrote:

 > If you want the included file to also have included files this needs to
 > be .php extension too

No it doesn't.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - <a style='text-decoration: underline;' href="http://www.goddamn.co.uk/tobyink/?page=132" target="_blank">http://www.goddamn.co.uk/tobyink/?page=132</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
beelymagee

External


Since: May 11, 2004
Posts: 5



(Msg. 10) Posted: Tue Jun 22, 2004 3:07 am
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Viper, Matthias, Mark, and Toby

On Mon, 21 Jun 2004 04:06:33 -0400
"Viper" <venomx RemoveThis @gmail.com> wrote:

 >
 > Here is what I use in my PHP pages
 > <? include("account_menu.php");?>
 >
 > in the account_menu.php is plain HTML

I wanted to thank you all for your responses --corrections and
suggestions. All of them are much appreciated. I haven't been able to
get the INCLUDE command to work yet in php nor SSI, but will be looking
at trying the commands to read from the file.

-*-Bill

Windows has detected that your mouse has moved,
please wait while Windows reboots for your changes to take effect.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
tobyink

External


Since: Apr 25, 2004
Posts: 148



(Msg. 11) Posted: Tue Jun 22, 2004 11:09 am
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Bill M. wrote:

 > Here's some php code to see output. I'm using php 4.3.3 (from a php,
 > MySQL, Apache book CD.) I have Apache2

Go to this page:
<a style='text-decoration: underline;' href="http://localhost/server-info" target="_blank">http://localhost/server-info</a>

Is mod_php4 listed near the top?

--
Toby A Inkster BSc (Hons) ARCS
Contact Me - <a style='text-decoration: underline;' href="http://www.goddamn.co.uk/tobyink/?page=132" target="_blank">http://www.goddamn.co.uk/tobyink/?page=132</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
spamhere1

External


Since: Mar 02, 2004
Posts: 3



(Msg. 12) Posted: Tue Jun 22, 2004 11:15 am
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Mon, 21 Jun 2004 16:29:41 -0700, Bill M. wrote:

 ><html>
 ><head>
 ><title>Testing INCLUDE command</title>
 ></head>
 ><body>
 ><p> Here's some text to show that this PHP file is working ...</p>
 ><?php
  > echo "<BR />";
  > echo "<BR />";
  > echo "<h1>Here is some other text ECHOed from the PHP command
 >file</h1>";
  > if (file_exists("navMenus.php")) {
   > echo "<h3>The Navigation Menus file exists according to
 >PHP!</h3>"; }
  > if (is_readable("navMenus.php")) {
   > echo "<h3>An the Navigation Menus file is READable to
 >boot!</h3>"; }
 >?>
 >
 ><? include("navMenus.php"); ?>
 >
 ></body>
 ></html>
 >
 >Here's the output (in Opera 7.51 Linux) from the above:
 >
 >Here's some text to show that this PHP file is working ...
 >"; echo "
 >"; echo "
 >Here is some other text ECHOed from the PHP command file
 >if (file_exists("navMenus.php")) { echo "
 >The Navigation Menus file exists according to PHP!
 >"; } if (is_readable("navMenus.php")) { echo "
 >An the Navigation Menus file is READable to boot!
 >"; } ?>

It's not running the script as php so you have a configuration problem
in Apache. Have you given your script the .php extension? That's
usually the default but it can be configured to run php in htm and/or
html files although that's not my preferred way since it means it has
to look for php code in every htm(l) file.

I'd check that you are loading the PHP module in your Apache httpd.conf
and that you have

AddType application/x-httpd-php .php

in there as well if you are using the .php extension.

If you want more help you are welcome to email me.

--
Regards - Rodney Pont
The from address exists but is mostly dumped,
please send any emails to the address below
e-mail ngpsm4 (at) infohitsystems (dot) ltd (dot) uk<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
jstucklex

External


Since: Jul 14, 2003
Posts: 1507



(Msg. 13) Posted: Wed Jun 23, 2004 11:31 am
Post subject: Re: Including Files--PHP or Perl? [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Bill M. wrote:
 >
 > Viper, Matthias, Mark, and Toby
 >
 > On Mon, 21 Jun 2004 04:06:33 -0400
 > "Viper" <venomx.DeleteThis@gmail.com> wrote:
 >
  > >
  > > Here is what I use in my PHP pages
  > > <? include("account_menu.php");?>
  > >
  > > in the account_menu.php is plain HTML
 >
 > I wanted to thank you all for your responses --corrections and
 > suggestions. All of them are much appreciated. I haven't been able to
 > get the INCLUDE command to work yet in php nor SSI, but will be looking
 > at trying the commands to read from the file.
 >
 > -*-Bill
 >
 > Windows has detected that your mouse has moved,
 > please wait while Windows reboots for your changes to take effect.

Bill,

You may have a problem with your file extensions.

The default extension for files with SSI is generally .shtml, and for
files containing PHP it's .php (sometimes also .php3 and php4) and is
case sensitive.

This can be overridden in your Apache configuration (and possibly with
..htaccess - I haven't tried). But if you coded the extension as .html
it won't work unless you change your configuration.

--

To reply, delete the 'x' from my email
Jerry Stuckle,
JDS Computer Training Corp.
jstucklex.DeleteThis@attglobal.net
Member of Independent Computer Consultants Association - <a style='text-decoration: underline;' href="http://www.icca.org" target="_blank">www.icca.org</a><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Including Files--PHP or Perl? 
Back to top
Login to vote
Display posts from previous:   
   Web Hosting Problem Solving Community! (Home) -> Webmaster All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]