include() does not work

Status
Not open for further replies.

zikozeb

New Member
Messages
12
Reaction score
0
Points
0
Hi

I have simple website. The main structure is based on header, main content and footer as below:

Code:
<?php
    include($_SERVER['DOCUMENT_ROOT'.'/header.php');
?>
<p>something here which contains main content</p>
<?php
    include($_SERVER['DOCUMENT_ROOT'.'/footer.php');
?>
Because I am going to use a couple of subscripts which are supposed to have the same header and footer I thought include woudl work perfect here. Unfortunately, the script is not run. It says include is not recognized text to parse. Is it something I am doing wrong or include simply does not exist? Is there any other way to make it work?

Regards.
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
two ] are missing :)
PHP:
<?php
    include($_SERVER['DOCUMENT_ROOT'].'/header.php');
?>
<p>something here which contains main content</p>
<?php
    include($_SERVER['DOCUMENT_ROOT'].'/footer.php');
?>
 

zikozeb

New Member
Messages
12
Reaction score
0
Points
0
two ] are missing :)
PHP:
<?php
    include($_SERVER['DOCUMENT_ROOT'].'/header.php');
?>
<p>something here which contains main content</p>
<?php
    include($_SERVER['DOCUMENT_ROOT'].'/footer.php');
?>

Two of ']' <- this?

Where? I cannot see that. Anyway, this is really not problem as syntax is incorrect. I have a impression that include is not a recognized function in version of PHP I am using.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
I have a impression that include is not a recognized function in version of PHP I am using.

Which version, PHP 0.2 ?
Seriously, you come across as someone who doesn't know what he is talking about.


PHP:
YOU:
include($_SERVER['DOCUMENT_ROOT'.'/header.php');
CORRECT:
include($_SERVER['DOCUMENT_ROOT'].'/header.php');

You really can't see the difference?
 

zikozeb

New Member
Messages
12
Reaction score
0
Points
0
PHP:
YOU:
include($_SERVER['DOCUMENT_ROOT'.'/header.php');
CORRECT:
include($_SERVER['DOCUMENT_ROOT'].'/header.php');
You really can't see the difference?
Yes I can now. I have not seen that before. I wanted to appologize Scoochi2

Scoochi2: The mistake was made because I have written this here from scratch and in my script everything's correct but it still does not work. So the main question is if function include() is working if I upload PHP script here?

Which version, PHP 0.2 ?
Seriously, you come across as someone who doesn't know what he is talking about.
Skip this this thread next time please, because if you really think I don't know what I am talking about only because I have not seen something in my code, I dont want you to participate with this discussion. You as programmer should know the most difficult is to find your own mistakes. I made just one mistake which I did not see and you have treated me like a total nOOb.

Please just skip it next time, don't come here, don't judge me and say what I am.

Please.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
It's not that I don't enjoy watching internet flames war go on - it's quite funny from the sidelines - but I would ask that descalo don't comment on this and that zikozeb doesn't add anything, so that this doesn't become a hate post.

Thanks. -if needed, a moderator could close this-
 

zikozeb

New Member
Messages
12
Reaction score
0
Points
0
It might not have stated clearly what was the main problem in this post. My english is not a first language and it's sometimes a reason i cannot precisely express my thoughts.

My website will consist of 3 parts: header, footer and main content in the middle. I don't want to repeat in every script exactly those parts which are in header and footer. On my localhost I have used PHP function include(), which is supposed to add header and footer, in the similar way as below:
PHP:
<?php
    include($_SERVER['DOCUMENT_ROOT'].'/header.php');
?>
<p>something here which contains main content</p>
<?php
    include($_SERVER['DOCUMENT_ROOT'].'/footer.php');
?>
The script works here at my localhost server. Once I have uploaded the example script with both functions include(), the server has showed information that in the line where this function is placed, there's a syntax error. As I was very surprised why, I have checked if this function exists at all. I have tied another script:
PHP:
if(function_exists('include'));
and it's returned false.

My question is what I am doing wrong. Why I cannot include my header and footer. IS this due to limits on free hosting server?

Thanks for any suggestions.
 

Livewire

Abuse Compliance Officer
Staff member
Messages
18,169
Reaction score
216
Points
63
php.net Function_Exists Manual said:
Note: This function will return FALSE for constructs, such as include_once() and echo().

Include's a construct, not technically a function, so it'll return false although it exists.

Other than that, I can't see why the code itself isn't working - it should be, but try just doing include("header.php"); and include("footer.php");


Never really needed $_SERVER['document_root'] on my stuff on x10, although it's been a long while since I was doing it on a free server. Worth a shot to take it out though just to see if it works, since it isn't right now anyways :)
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
The code itself you have posted is fine and it should be working. Maybe there is a problem within either the header or footer pages.

Can you post both of these in addition to the exact error message that appears when you try to run the page (copy paste it)?
 

zikozeb

New Member
Messages
12
Reaction score
0
Points
0
I have just tried what Livewire has suggested, which means I have tried the short form:

PHP:
include("header.php");
and
PHP:
include("footer.php");
and it started working.

When I tried this with single apostrophe, for instance:
PHP:
include('header.php');

it seemed not to work. Well, it was probably only me and my mistake. First time I must have had to missed square bracket ']' although I cannot believe that and second time, I had to mix single with double apostrophe. Anyway, it started working. As far as I remember the error that PHP showed on scree was similar to: "Parse: Syntax error (...) at line 4" etc.

Thanks for any help and I hope I have not made too much mess in this thread.
 

xav0989

Community Public Relation
Community Support
Messages
4,467
Reaction score
95
Points
0
The Parse: Syntax error should have warned you that it was in fact an error in the code you type. Now you'll know!
 

wfarr_0817

New Member
Messages
5
Reaction score
0
Points
0
what version of PHP does this host even have? definitly 4.0+...cuz i have wp running just fine.
 
Status
Not open for further replies.
Top