/    Sign up×
Community /Pin to ProfileBookmark

inlude in an Echo

hi sorry…

but how should I include an extern page within an already exixting php script after echo?

now it is like this…

[code=php] echo “</head><body>n”;
[/code]

And somehow I would like to include this [COLOR=Red]<? include(“includes/Meny.php”) ?>[/COLOR] within that echo after the body tag

or do I have to seperate it perhaps?

to post a comment
PHP

12 Comments(s)

Copy linkTweet thisAlerts:
@rch10007Sep 02.2005 — just curious, why are you trying to do that?

Have you read the manual? http://www.php.net/manual/en/function.include.php
Copy linkTweet thisAlerts:
@rch10007Sep 02.2005 — you can have an include() statement after the echo without anything special.

Just write the echo and on the next line put the include.

[code=php]
<?php
echo "</head><body>n";
include("includes/Meny.php") ;
?>
[/code]
Copy linkTweet thisAlerts:
@SiddanauthorSep 02.2005 — thanks..

the reason why I do that i cus I have found a glorious php script and there is a "Create HTML page" which only creates the first top half... html, meta tags, head and body.

Then there are various scripts in the middle before it ends with "End of HTML page" which are the closing tags for my inserted divs, the body and html.

So I am poorly trying to implement this whole php script to my existing site.... or rather I am actually trying to implement my site around this php script.

...it is a php script for fotoalbum if you wonder
Copy linkTweet thisAlerts:
@SiddanauthorSep 02.2005 — ah yes, that seems to work... just need to seperate the include from echo.

My following question is though... Doesn´t the include recognize the root path?

I would like to avoid this for an example:

include("../../../eng/Meny.php")

and to have like this instead...

include("/eng/Meny.php")

but it doesn´t seem to search from the root for that included php file. It works with all others like images so the root path is valid
Copy linkTweet thisAlerts:
@rch10007Sep 03.2005 — [code=php]include ( "http://" . $SERVER['HTTP_HOST'] . "/eng/meny.php" );[/code]

$SERVER['HTTP_HOST'] will give you = www.yourdomain.com

so the whole include should produce: http://www.yourdomain.com/eng/meny.php
Copy linkTweet thisAlerts:
@SiddanauthorSep 05.2005 — Thanks a bunch, that helped..

Now I have problems with margins when having my meny inside that album script.. arrgh. Hopefully I can solve it
Copy linkTweet thisAlerts:
@bokehSep 05.2005 — [code=php]include ( "http://" . $SERVER['HTTP_HOST'] . "/eng/meny.php" );[/code][/QUOTE]Why would you do that to call a file on the same server. Surely you would use a file path not an http path:[code=php]include($_SERVER['DOCUMENT_ROOT'] . '/eng/meny.php');[/code]
Copy linkTweet thisAlerts:
@rch10007Sep 05.2005 — This is from a post you replied to not long ago - this is why I gave him the answer I did.

http://www.webdeveloper.com/forum/showthread.php?t=76087

One last thing... I often see people using this construct:
[code=php]
echo ('<form action="'.$_SERVER['PHP_SELF'].'" method="post">'."n");
[/code]

but sometimes people save forms and fill them in later and it is very frustrating finding the form doesn't work only after having filled it in so I recommend:
[code=php]
echo ('<form action="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'" method="post">'."n"); [/code]

[/QUOTE]
Copy linkTweet thisAlerts:
@bokehSep 06.2005 — Hmm! I can see why you are confused. That is part of an html page so it will be used by a web browser to request a file. Since a web browser needs an http path (internet path) this code
[code=php]echo ('<form action="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'" method="post">'."n"); [/code] produces a URL style path. In the case of an include() things are different. For this a file path is needed.

Examples:

http path: http://domain.com/file.php

file path: c:/apache2/htdocs/file.php

If a path is going to be used by a browser it must be an http path and if a server wants to open a local file that should use a file path.
Copy linkTweet thisAlerts:
@rch10007Sep 06.2005 — ok, I was thinking that using the absolute URL you can include the include() in any directory and it will always reach the file no matter how deep your subdirectories go. In some case to have the included file you may have to use "../../../../../file.php" but I would just use the absolute URL so that way the script stays the same no matter where you are calling the file from.
Copy linkTweet thisAlerts:
@bokehSep 06.2005 — One of the problems with http paths is you can't write to them and also they are a completely separate request. Lastly if you include using a http path you will only be viewing the output of the file after parsing so for example, if you wanted to include a file and use a function it contained you can only use the file path. Even if the file is accessible with an http path the functions in the file will not be accessible.
Copy linkTweet thisAlerts:
@rch10007Sep 06.2005 — i understand. if I use:

include($_SERVER['DOCUMENT_ROOT'] . '/eng/meny.php');

i can use functions within the file but if I use HTTP_HOST then I am parsing the functions so they aren't available.

Thx for explaining that to me - I had no idea!
×

Success!

Help @Siddan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...