|
-
Jan 26th, 2003, 07:30 AM
#1
Including a header php page *finished*
I'd like to include a header.php page to serve as the top part of every php page I make. I'm aware that I can use include("header.php"), but I have a question...
Is include() the right way to go about it?
In ASP, I use the simple
VB Code:
<!--#include file="topinclude.asp"-->
Is it better to use this, or include()?
Any better ways?
Tx.
Last edited by mendhak; Jan 30th, 2003 at 12:46 AM.
-
Jan 26th, 2003, 08:06 AM
#2
Frenzied Member
Yep I think include is fine. The other alternative is require which will stop execution if the file is not found, whereas include will carry on.
-
Jan 26th, 2003, 10:32 AM
#3
erm...
include()
or
<!--#include-->
?
-
Jan 26th, 2003, 10:56 AM
#4
Stuck in the 80s
Originally posted by mendhak
erm...
include()
or
<!--#include-->
?
include()
<!--#include--> is SSI and would not work in PHP, unless you echoed it as an SSI.
include() is what I use. I've never had a problem with it.
-
Jan 26th, 2003, 11:48 AM
#5
-
Jan 26th, 2003, 12:30 PM
#6
Frenzied Member
Originally posted by Rick Bull
Yep I think include is fine. The other alternative is require which will stop execution if the file is not found, whereas include will carry on.
but, if include didn't find the file it will give you a warning. and still carry on. stil has an error so I think it would be the same as require.
-
Jan 27th, 2003, 06:14 AM
#7
Frenzied Member
Yep, but you can put an @ before it to surpress the error can't you? @include('file');
And sorry Mendhak, wasn't reading properly
-
Jan 27th, 2003, 08:54 AM
#8
Frenzied Member
yes you could, but getting in the habit of surpressing warnings or errors is a bad idea as the error or warning is there for a reason and should be taken care of.
the only time you should add a @ in front of something is if you make your own die() function after it.
-
Jan 27th, 2003, 11:06 AM
#9
I have another question:
I'm currently using
PHP Code:
include("../header.php");
The above code goes into a file that is in a folder in the root folder, and is including a header.php file that is in the root.
However, when I try to use
PHP Code:
include("/header.php");
to specify the same header.php file in the root folder, it won't work, and instead gives me an error message. I want to use this second piece of code instead of the first, since it will save an awful lot of work for me.
Any help?
-
Jan 27th, 2003, 12:22 PM
#10
I tried
PHP Code:
<?php
include("$DOCUMENT_ROOT/header.php");
?>
But I'm getting errors. I'm at the point of total confusion.
Any help at all appreciated!
-
Jan 27th, 2003, 02:31 PM
#11
Frenzied Member
do the full path
/usr/path/to/file.php
no ../ or http:// addys
also if you are using document_root you may need to use the $_SERVER['DOCUMENT_ROOT'] as register_globas is off.
-
Jan 27th, 2003, 03:11 PM
#12
Frenzied Member
Thanks phpman, I thought my server didn't support absolute paths, but it does now that I find the full path (using realpath()).
-
Jan 28th, 2003, 12:32 AM
#13
Originally posted by phpman
do the full path
/usr/path/to/file.php
no ../ or http:// addys
also if you are using document_root you may need to use the $_SERVER['DOCUMENT_ROOT'] as register_globas is off.
$_SERVER['DOCUMENT_ROOT'] wouldn't work for me, but I do have register_globals on. The strange thign is, I tried
include("/header.php");
and it works fine on MY pc (I have PWS configured to execute PHP pages), and on my server, I have to upload it with
include("$DOCUMENT_ROOT/header.php");
for it to work.
If I interchange these, I get errors. That is what I was wondering about.
Rick, I tried realpath() and it returns C:/ as the root!!!
-
Jan 28th, 2003, 12:44 AM
#14
Frenzied Member
the best way to do test scripts is to make your test server that exact same as your host server. in this case it sounds like your host has register globals off (which it should be this way for security reasons.) also it might be that they have apache too.
if you get your test server setup like your host then the less changes you have to make when you upload
-
Jan 28th, 2003, 06:33 AM
#15
Frenzied Member
And did you use realpath on the include bit, or the DOCUMENT_ROOT? It should have been this: include(realpath("/header.php"));
-
Jan 28th, 2003, 11:49 AM
#16
Stuck in the 80s
Originally posted by mendhak
$_SERVER['DOCUMENT_ROOT'] wouldn't work for me, but I do have register_globals on.
What version of PHP are you running? If it's older than 4.2 (or maybe even 4.1), then the superglobals aren't available.
-
Jan 28th, 2003, 04:48 PM
#17
Frenzied Member
True, I am using the superglobals and I am on 4.1
-
Jan 28th, 2003, 08:50 PM
#18
Er... how do I tell what version I'm using? :embarrased:
-
Jan 28th, 2003, 08:56 PM
#19
Originally posted by Rick Bull
And did you use realpath on the include bit, or the DOCUMENT_ROOT? It should have been this: include(realpath("/header.php"));
Yeah, and it was searching for header.php in c:\ 
I have a feeling that this is due to the version differences. I have the PHP binary which 'auto configured' itself for PWS. The server runs on Linux, and uses Apache....
-
Jan 28th, 2003, 09:24 PM
#20
Frenzied Member
make a file and call it wahtever you want, info.php
then ad this to it and run it
<?php
phpinfo();
?>
that is all you put in the file.
-
Jan 29th, 2003, 04:57 AM
#21
4.3.0 !!
I'll put up a link to the HTML page in a while, so you can look at it...
-
Jan 29th, 2003, 05:00 AM
#22
I ran phpinfo() and I saved the page as html, uploaded it here:
http://mendhak.worldjunkie.com/phpinfo.html
Then I uploaded the php page onto the server itself, so this link shows the SERVER configuration:
http://mendhak.worldjunkie.com/chicken.php
-
Jan 29th, 2003, 05:03 AM
#23
doc_root no value no value
Could that be the problem?
Last edited by mendhak; Jan 29th, 2003 at 05:06 AM.
-
Jan 29th, 2003, 08:02 AM
#24
Conquistador
does it not work just
include('header.php');
it's in the same directory as the file which is including it isn't it?
-
Jan 29th, 2003, 08:44 AM
#25
Originally posted by da_silvy
does it not work just
include('header.php');
it's in the same directory as the file which is including it isn't it?
header.php is in the root directory. Any php files in the root directly using include() work just fine. The problem comes up when I'm trying to include it from a php file in a subdirectory. That's why you see so many $DOCUMENT_ROOTs floating around in this thread
-
Jan 29th, 2003, 09:05 AM
#26
Frenzied Member
ok I see a lot of differences.
for one you have 4.3, your host has 4.2.3 (big differences)
you host has register_globals OFF, you have them ON
you have it setup as cgi, your host is setup as a module. that will be a difference right there.
here is your path. (on host)
/home/butterfl/public_html/mendhak/chicken.php
so when you inlcude something that is NOT in the root it will be like this.
include("/home/butterfl/public_html/mendhak/folder/chicken.php");
so basically that will work like this
include("folder/chicken.php");
samething.....
the fact that you don't have a document root is bad. you should have one. I believe your install is all messed up.
what server do you have?
hope you didn't install that Triad thing. tht is the biggest pile of dog dodo 
for one, on your test machine you shouldn't have virtual directories enabled, no need for them. you shuold have globals OFF, you should have doc_root
-
Jan 29th, 2003, 01:30 PM
#27
Originally posted by phpman
you host has register_globals OFF, you have them ON
If I register_globals OFF, will I still be able to access the $POST and $GET info from forms?
the fact that you don't have a document root is bad. you should have one. I believe your install is all messed up.
what server do you have?
I downloaded the PHP binary from php.net, and chose the option to configure it for PWS. How can I have a document root now?
Is it possible in any way? Or should I continue with the different include() for both machines?
-
Jan 29th, 2003, 04:42 PM
#28
Frenzied Member
$_POST and $_GET are used when globals are OFF. if you had globals ON then you can just acces the variables without the POST or GET.
I would download apache. not sure where in PWS is the config (or if it even has one) to adjust the doc_root. Apache is your best bet as your host has it too.
-
Jan 30th, 2003, 12:46 AM
#29
Alright.
Thanks to everyone for the input and for the patience they've shown here.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|