Professional Web Applications Themes

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

[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 ...

  1. #1

    Default 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_basis?>favicon.ico"
    type="image/x-icon">
    <LINK rel="shortcut icon" href="<?=$nav_basis?>favicon.ico"
    type="image/x-icon">
    <LINK rel="stylesheet" href="<?=$nav_basis?>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 p
    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
    Zaan Guest

  2. #2

    Default Re: A very annoying require() -and include()- problem.


    "Zaan" <net> wrote in message
    news:300120041643149487%net... 
     

    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)

    Gerard Guest

  3. #3

    Default Re: A very annoying require() -and include()- problem.

    In article <bvedh2$hu6$wxs.nl>, Gerard van Wilgen
    <nl> wrote:
     

    >
    > Is the closing double quote in the original code missing as well?
    >
    >
    > Gerard van Wilgen[/ref]

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

    Zaan
    Zaan Guest

  4. #4

    Default Re: A very annoying require() -and include()- problem.

    The text editor saved your .php file as Unicode?

    Uzytkownik "Zaan" <net> napisal w wiadomosci
    news:300120041643149487%net... 


    Chung Guest

  5. #5

    Default Re: A very annoying require() -and include()- problem.

    Zaan <net_andthistoo> wrote in message news:<310120040126327571%net_andthistoo>... [/ref]

    > >
    > > Is the closing double quote in the original code missing as well?
    > >
    > >
    > > Gerard van Wilgen[/ref]
    >
    > No, it is not missing in the original. I must have falsely edited it
    > out here.
    >
    > Zaan[/ref]

    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 pd properly by PHP engine.

    --
    Hope it will help,
    Rahul Anand
    Rahul Guest

  6. #6

    Default Re: A very annoying require() -and include()- problem.

    In article <com>, Chung Leong
    <com> wrote:
     
    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




     
    >
    >[/ref]
    Zaan Guest

  7. #7

    Default Re: A very annoying require() -and include()- problem.

    "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 pr doesn't see the sequence
    "<?php" therefore the code doesn't get pd.

    Uzytkownik "Zaan" <net_andthistoo>
    napisal w wiadomosci
    news:010220042103440168%net_andthi
    stoo... 
    > 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
    >
    >
    >
    >
    > [/ref]
    wiadomosci [/ref][/ref]
    which [/ref][/ref]
    if [/ref][/ref]
    file, [/ref][/ref]
    executed, [/ref][/ref]
    is 
    > >
    > >[/ref][/ref]


    Chung Guest

Similar Threads

  1. PHP require or include and Contribute 3
    By gerrypez in forum Macromedia Contribute General Discussion
    Replies: 2
    Last Post: March 3rd, 07:05 AM
  2. Absolute URLs with Require & Include
    By Seth Willits in forum PHP Development
    Replies: 1
    Last Post: August 29th, 01:08 PM
  3. [PHP] Performance and require / include
    By Curt Zirzow in forum PHP Development
    Replies: 0
    Last Post: July 18th, 11:57 PM
  4. Replies: 0
    Last Post: July 10th, 04:37 PM
  5. #24593 [NEW]: class not instantiated problem with include/require
    By ssem at complexusgroup dot com in forum PHP Development
    Replies: 0
    Last Post: July 10th, 04:31 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139