Re: Very newbie question (including other php files)
am 10.11.2005 14:22:53 von dan
Unfortunately it still doesn't work. I've put a cut-down example of this on my website.
The source code is here ...
www.dracan.co.uk/index_test_php.txt
www.dracan.co.uk/header_test_php.txt
and the actual pages are here ...
www.dracan.co.uk/index_test.php
www.dracan.co.uk/header_test.php
I'm sure it must be something simple, but I can't for the life of me see what it is. Then again, I am extremely new to php.
Thanks for your help with this,
Regards,
Dan.
"Hilarion" wrote in message news:dkvb8l$de8$1@news.onet.pl...
> > If I've got one file called header.php that contains the following code ...
> >
> >
> >
> >
>
> You do not need quotes around variable. The instruction should
> look like this:
> echo $title_string;
> or even:
> echo htmlspecialchars( $title_string );
>
> >
> >
> >
> > and I've got index.php that contains the following code ...
> >
> >
> >
>
> You do not need to use two PHP sections. You can join the
> code into one section for example like this (I used single
> quotes because they do not evaluate special chars which
> makes using "$" sign and quotes in those easier):
>
>
> $title_string = 'My Title String';
> include 'header.php';
> ?>
>
> > Main body contents
> >
> >
> > Why is the $title_string variable empty (or undefined) in header.php?
> > Basically, my actual header.php is a lot bigger, and I want
> > all my webpages to include this header, but specifying different options
> > - ie. the title string, and a few others.
>
> This example above should work (even with those quotes around variable
> in the header file). Have you checked if this simple example works on your
> PHP server? If not, then check it. If this one works, and your actual code
> does not, then you have some error in the actual code. We'd have to see it
> to tell what is wrong with it.
>
>
> Hilarion
Re: Very newbie question (including other php files)
am 10.11.2005 14:38:35 von Hilarion
> Unfortunately it still doesn't work. I've put a cut-down example of this on my website.
>
> The source code is here ...
>
> www.dracan.co.uk/index_test_php.txt
> www.dracan.co.uk/header_test_php.txt
>
> and the actual pages are here ...
>
> www.dracan.co.uk/index_test.php
> www.dracan.co.uk/header_test.php
>
> I'm sure it must be something simple, but I can't for the life of me see what it is.
> Then again, I am extremely new to php.
It is something simple. The problem is in the way you include your header
file. You did it by providing URL, not path to the file. This way the
header file got interpreted (executed) in separate HTTP request (so
no variable value was there) and the interpretation result (pure
HTML) got included into the index file. You should use local path (in terms
of PHP server local path) when including files. In this case (when included
file is in the same folder as the scirpt including it) you can simply
give included file name without any path information:
$title_string = 'My title string';
include 'header_test.php';
?>
This is the main body