473,805 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A very annoying require() -and include()- problem.


[I'm working on PHP version 4.3.4 (which may be of importance, I don't
know). It's the vanilla precompiled www.entropy.ch release for Mac OS
X.]

Hello,

My issue is the following: to promote consistency on a site I'm
building, I decided to go for a php scheme where some recurring
elements (navigation, mostly) are written in a file of their own, which
would then get called from each file needing it by the function
require(). The following example may make this clear (the HTML is
clipped somewhat, but is W3C compliant in full...):

Suppose this is the main file, text.php
<?php require('./lib/head_1.php'); ?>
<TITLE>text</TITLE>
<?php require('./lib/head_2.php'); ?>
the actual body text, html formatted, would go here.
<?php require './lib/foot.php'; ?>
Then, head_1.php would look like:
<?php $nav_basis = "http://localhost/~username/; ?> // will
change once the site is done and is uploaded to the actual server, of
course.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<LINK rel="icon" href="<?=$nav_b asis?>favicon.i co"
type="image/x-icon">
<LINK rel="shortcut icon" href="<?=$nav_b asis?>favicon.i co"
type="image/x-icon">
<LINK rel="stylesheet " href="<?=$nav_b asis?>lib/zaan.css"
type="text/css">
and head_2.php would look like:

</HEAD>
<BODY>
<div>

etcetera, in short: navigational elements with css formatting.

The main point is the variable $nav_basis, which is needed because not
all my files are in the same directory, and I would really would like
to have one file with standard stuff that works throughout the site as
it should. You might suggest using the <BASE> tag in html, but that is
no good: many files on the site are older and large html files with
ample relative crossreferences , which will irrevocably get broken by
such a tag, not to mention get a lot more confusing during future
updates.

My problem now is that Apache, or its PHP module won't properly parse
the PHP that I require(). I do not understand this. The PHP manual
seems to imply that PHP code in an require()ed file will be executed if
tagged properly, but I am having no luck.
As a result, the source file sent to my browser (by Apache, mind you,
not the local filesystem) contains the two head_x.php files as clear
text, showing <?php tags and everything as they are in the source file,
and nothing executed, obviously.
PHP code that I'd write in the main file (text.php) would get executed,
however.
include() shows the same behaviour.

I wonder what the problem is here. Is it my installation of PHP that is
faulty, is it something that I forgot, is it something else?

Can anybody help?

Thanks in advance,
Zaan
Jul 17 '05 #1
6 4394

"Zaan" <removethis_zaa n@removethis_gm x.net> wrote in message
news:3001200416 43149487%remove this_zaan@remov ethis_gmx.net.. .
<?php $nav_basis = "http://localhost/~username/; ?>


Is the closing double quote in the original code missing as well?
Gerard van Wilgen
--
www.majstro.com (On-line translation dictionary / Enreta tradukvortaro)
www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga
tradukvortaro por Windows)

Jul 17 '05 #2
In article <bv**********@r eader11.wxs.nl> , Gerard van Wilgen
<gv********@pla net.nl> wrote:
"Zaan" <removethis_zaa n@removethis_gm x.net> wrote in message
news:3001200416 43149487%remove this_zaan@remov ethis_gmx.net.. .

<?php $nav_basis = "http://localhost/~username/; ?>


Is the closing double quote in the original code missing as well?
Gerard van Wilgen


No, it is not missing in the original. I must have falsely edited it
out here.

Zaan
Jul 17 '05 #3
The text editor saved your .php file as Unicode?

Uzytkownik "Zaan" <removethis_zaa n@removethis_gm x.net> napisal w wiadomosci
news:3001200416 43149487%remove this_zaan@remov ethis_gmx.net.. .

[I'm working on PHP version 4.3.4 (which may be of importance, I don't
know). It's the vanilla precompiled www.entropy.ch release for Mac OS
X.]

Hello,

My issue is the following: to promote consistency on a site I'm
building, I decided to go for a php scheme where some recurring
elements (navigation, mostly) are written in a file of their own, which
would then get called from each file needing it by the function
require(). The following example may make this clear (the HTML is
clipped somewhat, but is W3C compliant in full...):

Suppose this is the main file, text.php
<?php require('./lib/head_1.php'); ?>
<TITLE>text</TITLE>
<?php require('./lib/head_2.php'); ?>
the actual body text, html formatted, would go here.
<?php require './lib/foot.php'; ?>
Then, head_1.php would look like:
<?php $nav_basis = "http://localhost/~username/; ?> // will
change once the site is done and is uploaded to the actual server, of
course.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<LINK rel="icon" href="<?=$nav_b asis?>favicon.i co"
type="image/x-icon">
<LINK rel="shortcut icon" href="<?=$nav_b asis?>favicon.i co"
type="image/x-icon">
<LINK rel="stylesheet " href="<?=$nav_b asis?>lib/zaan.css"
type="text/css">
and head_2.php would look like:

</HEAD>
<BODY>
<div>

etcetera, in short: navigational elements with css formatting.

The main point is the variable $nav_basis, which is needed because not
all my files are in the same directory, and I would really would like
to have one file with standard stuff that works throughout the site as
it should. You might suggest using the <BASE> tag in html, but that is
no good: many files on the site are older and large html files with
ample relative crossreferences , which will irrevocably get broken by
such a tag, not to mention get a lot more confusing during future
updates.

My problem now is that Apache, or its PHP module won't properly parse
the PHP that I require(). I do not understand this. The PHP manual
seems to imply that PHP code in an require()ed file will be executed if
tagged properly, but I am having no luck.
As a result, the source file sent to my browser (by Apache, mind you,
not the local filesystem) contains the two head_x.php files as clear
text, showing <?php tags and everything as they are in the source file,
and nothing executed, obviously.
PHP code that I'd write in the main file (text.php) would get executed,
however.
include() shows the same behaviour.

I wonder what the problem is here. Is it my installation of PHP that is
faulty, is it something that I forgot, is it something else?

Can anybody help?

Thanks in advance,
Zaan

Jul 17 '05 #4
Zaan <removethis_zaa n_andthistoo@re movethis_gmx.ne t_andthistoo> wrote in message news:<310120040 126327571%remov ethis_zaan_andt histoo@removeth is_gmx.net_andt histoo>...
In article <bv**********@r eader11.wxs.nl> , Gerard van Wilgen
<gv********@pla net.nl> wrote:
"Zaan" <removethis_zaa n@removethis_gm x.net> wrote in message
news:3001200416 43149487%remove this_zaan@remov ethis_gmx.net.. .
<?php $nav_basis = "http://localhost/~username/; ?>


Is the closing double quote in the original code missing as well?
Gerard van Wilgen


No, it is not missing in the original. I must have falsely edited it
out here.

Zaan


Check the HTML Source you are getting in browser, when you execute the script.
Are you getting the PHP source code or the output?
I guess the problem is not in *require* or *include* but some wrong pathing.

All required & included files with proper tags are parsed properly by PHP engine.

--
Hope it will help,
Rahul Anand
Jul 17 '05 #5
In article <Hq************ ********@comcas t.com>, Chung Leong
<ch***********@ hotmail.com> wrote:
The text editor saved your .php file as Unicode?
It was. Disabling 'Encode as Unicode' solved the problem. A very good
suggestion! Thanks a lot for that. Do you happen to know why this
problem occured?

Zaan


Uzytkownik "Zaan" <removethis_zaa n@removethis_gm x.net> napisal w wiadomosci
news:3001200416 43149487%remove this_zaan@remov ethis_gmx.net.. .

[I'm working on PHP version 4.3.4 (which may be of importance, I don't
know). It's the vanilla precompiled www.entropy.ch release for Mac OS
X.]

Hello,

My issue is the following: to promote consistency on a site I'm
building, I decided to go for a php scheme where some recurring
elements (navigation, mostly) are written in a file of their own, which
would then get called from each file needing it by the function
require(). The following example may make this clear (the HTML is
clipped somewhat, but is W3C compliant in full...):

Suppose this is the main file, text.php
<?php require('./lib/head_1.php'); ?>
<TITLE>text</TITLE>
<?php require('./lib/head_2.php'); ?>
the actual body text, html formatted, would go here.
<?php require './lib/foot.php'; ?>
Then, head_1.php would look like:
<?php $nav_basis = "http://localhost/~username/; ?> // will
change once the site is done and is uploaded to the actual server, of
course.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<LINK rel="icon" href="<?=$nav_b asis?>favicon.i co"
type="image/x-icon">
<LINK rel="shortcut icon" href="<?=$nav_b asis?>favicon.i co"
type="image/x-icon">
<LINK rel="stylesheet " href="<?=$nav_b asis?>lib/zaan.css"
type="text/css">
and head_2.php would look like:

</HEAD>
<BODY>
<div>

etcetera, in short: navigational elements with css formatting.

The main point is the variable $nav_basis, which is needed because not
all my files are in the same directory, and I would really would like
to have one file with standard stuff that works throughout the site as
it should. You might suggest using the <BASE> tag in html, but that is
no good: many files on the site are older and large html files with
ample relative crossreferences , which will irrevocably get broken by
such a tag, not to mention get a lot more confusing during future
updates.

My problem now is that Apache, or its PHP module won't properly parse
the PHP that I require(). I do not understand this. The PHP manual
seems to imply that PHP code in an require()ed file will be executed if
tagged properly, but I am having no luck.
As a result, the source file sent to my browser (by Apache, mind you,
not the local filesystem) contains the two head_x.php files as clear
text, showing <?php tags and everything as they are in the source file,
and nothing executed, obviously.
PHP code that I'd write in the main file (text.php) would get executed,
however.
include() shows the same behaviour.

I wonder what the problem is here. Is it my installation of PHP that is
faulty, is it something that I forgot, is it something else?

Can anybody help?

Thanks in advance,
Zaan


Jul 17 '05 #6
"Saving as Unicode" usually means saving as UCS-16. It's a 2-byte encoding.
When you save your PHP file as Unicode, the content becomes

<[]?[]p[]h[]p[] [] .... ?[]>[]

where [] is a null character. The PHP parser doesn't see the sequence
"<?php" therefore the code doesn't get parsed.

Uzytkownik "Zaan" <removethis_zaa n_andthistoo@re movethis_gmx.ne t_andthistoo>
napisal w wiadomosci
news:0102200421 03440168%remove this_zaan_andth istoo@removethi s_gmx.net_andth i
stoo...
In article <Hq************ ********@comcas t.com>, Chung Leong
<ch***********@ hotmail.com> wrote:
The text editor saved your .php file as Unicode?

It was. Disabling 'Encode as Unicode' solved the problem. A very good
suggestion! Thanks a lot for that. Do you happen to know why this
problem occured?

Zaan


Uzytkownik "Zaan" <removethis_zaa n@removethis_gm x.net> napisal w wiadomosci news:3001200416 43149487%remove this_zaan@remov ethis_gmx.net.. .

[I'm working on PHP version 4.3.4 (which may be of importance, I don't
know). It's the vanilla precompiled www.entropy.ch release for Mac OS
X.]

Hello,

My issue is the following: to promote consistency on a site I'm
building, I decided to go for a php scheme where some recurring
elements (navigation, mostly) are written in a file of their own, which would then get called from each file needing it by the function
require(). The following example may make this clear (the HTML is
clipped somewhat, but is W3C compliant in full...):

Suppose this is the main file, text.php
<?php require('./lib/head_1.php'); ?>
<TITLE>text</TITLE>
<?php require('./lib/head_2.php'); ?>
the actual body text, html formatted, would go here.
<?php require './lib/foot.php'; ?>
Then, head_1.php would look like:
<?php $nav_basis = "http://localhost/~username/; ?> // will
change once the site is done and is uploaded to the actual server, of
course.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<LINK rel="icon" href="<?=$nav_b asis?>favicon.i co"
type="image/x-icon">
<LINK rel="shortcut icon" href="<?=$nav_b asis?>favicon.i co"
type="image/x-icon">
<LINK rel="stylesheet " href="<?=$nav_b asis?>lib/zaan.css"
type="text/css">
and head_2.php would look like:

</HEAD>
<BODY>
<div>

etcetera, in short: navigational elements with css formatting.

The main point is the variable $nav_basis, which is needed because not
all my files are in the same directory, and I would really would like
to have one file with standard stuff that works throughout the site as
it should. You might suggest using the <BASE> tag in html, but that is
no good: many files on the site are older and large html files with
ample relative crossreferences , which will irrevocably get broken by
such a tag, not to mention get a lot more confusing during future
updates.

My problem now is that Apache, or its PHP module won't properly parse
the PHP that I require(). I do not understand this. The PHP manual
seems to imply that PHP code in an require()ed file will be executed if tagged properly, but I am having no luck.
As a result, the source file sent to my browser (by Apache, mind you,
not the local filesystem) contains the two head_x.php files as clear
text, showing <?php tags and everything as they are in the source file, and nothing executed, obviously.
PHP code that I'd write in the main file (text.php) would get executed, however.
include() shows the same behaviour.

I wonder what the problem is here. Is it my installation of PHP that is faulty, is it something that I forgot, is it something else?

Can anybody help?

Thanks in advance,
Zaan


Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
1803
by: Elbert Lev | last post by:
# here is the problem I ran into: class foo: def __init__(self, host): self.f() self.r = True def f(self): if self.r: #<do something>
0
1734
by: Uri Dor | last post by:
after debugging ends, the text editor (VS.NET 2003) doesn't scroll so the line the cursor on is visible. annoying!
4
2505
by: Patrick LeBoutillier | last post by:
Hi all, Is there anyway to be notified when the use/require of a module fails? Basically I would like to setup a sub that gets called whenever a use/require call doesn't find what it is looking for. Sort of an AUTOLOAD but for use/require. Any ideas?
2
2215
by: Simon Wigzell | last post by:
Can I turn off that annoying little box with the save/print/send etc. icons in it that IE pops up whenever I mouseover a picture in my browser? I mean in my own web pages is there something I can add to the <img> tag to prevent this rather than turn it off in the browser (Though that would be good too! Same thing is available through right mouse click, who needs it???) Thanks!
0
1213
by: Daniel Lidström | last post by:
Hi, why is the cursor placed in the output view after a completed build? Also, why when I type F4 to find out errors, is the cursor still in the output view? Visual Studio 6.0 moved the cursor to the code view, now I have to either use the mouse or ctrl-tab two times to place the cursor at the error location. In my opinion this is very annoying. Does anyone agree? IDE version: 7.1.3088 --
2
1375
by: Daniel Lidström | last post by:
Hi, how can I have the cursor move back into the code window instead of the output window after a compile? It is very annoying to have to type ctrl-tab, ctrl-tab, to move the cursor back into the code. P.S. I do not want to use the mouse for this. VC6.0 did it just the way I like it. --
52
5222
by: Michael Hopkins | last post by:
Hi all We all know that C++ is a cleverly conceived multi-paradigm language that sacrifices very little in efficiency for what it delivers in terms of type-safety, encapsulation and generic behaviour. What I want to ask here is - what are the features that people most dislike about it i.e. that: - make it more difficult than necessary to implement designs
4
3114
by: rhob60 | last post by:
Everytime I log on to Yahoo.com I get this annoying ASP BROWSER WARNING notice, telling me I need special softward (which I already have) to delete files from my hard drive. Is there anyway to turn this thing off? It's really, really annoying!
84
7236
by: braver | last post by:
Is there any trick to get rid of having to type the annoying, character-eating "self." prefix everywhere in a class? Sometimes I avoid OO just not to deal with its verbosity. In fact, I try to use Ruby anywhere speed is not crucial especially for @ prefix is better- looking than self. But things grow -- is there any metaprogramming tricks or whatnot we can throw on the self? Cheers,
6
1432
by: geoffbache | last post by:
Hi all, I find that I semi-frequently get the cryptic message import site failed; use -v for traceback printed on standard error when an arbitrary python script receives SIGINT while the python interpreter is still firing up. If I use -v for traceback I get something along the lines of
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5542
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.