View Full Version : how to include text through PHP
adil
May 20th, 2006, 19:37
hey all,
I have a text and few links that I need to be at every webpage of the website.
How can I do that ?
Do anyone have any idea ?
the_pm
May 20th, 2006, 19:40
<?php include($DOCUMENT_ROOT . "/includes/stuff.xyz"); ?>That goes into every page where you want stuff included.
Then, create the file stuff.xyz, and place it in your includes/ folder (you can create any path you want to your includes - the path in the code above is just an example).
adil
May 20th, 2006, 19:50
thanks alot
chaos
May 20th, 2006, 22:34
I suppose you could always use frames, but I am totally against frames in every way possible. You could also use CSS "content", although I along with most people here disagree with it. I would suggest the PHP route to be the best.
:hi: A few comments to that:
Number 1:
In PHP 4.2.0 and later, the default value for the PHP directive register_globals is off. This is a major change in PHP. Having register_globals off affects the set of predefined variables available in the global scope. For example, to get DOCUMENT_ROOT you'll use $_SERVER['DOCUMENT_ROOT'] instead of $DOCUMENT_ROOT
Number 2:
Use single quotes '...' instead of double quotes "...". Only use double quotes if you use variables within them. PHP searches double quotes for variables thus making it slower.
$foo = bar;
print '$foo'; // this would print '$foo'
print "$foo"; // this would print 'bar'
So the correct way would be:
<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/stuff.xyz'); ?>
the_pm
May 23rd, 2006, 19:24
Good information. Thanks jos :)
crazyfish
May 23rd, 2006, 19:38
Hey,
Out of curiosity what is the difference between:
<?php include("./file.html"); ?>
and
<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/stuff.xyz'); ?>
Jamie
May 23rd, 2006, 19:49
I'm not sure of the exact difference, Nick, but I do believe the latter will not work with PHP3. We did a recent server migration, which involved a PHP upgrade, and as a result, some customers who were using the latter method that you describe above were having problems. Reverting to the first method solved the problem.
sea otter
May 23rd, 2006, 21:09
Hey,
Out of curiosity what is the difference between:
<?php include("./file.html"); ?> and
<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/stuff.xyz'); ?>
This is actually more complicated than it seems.
./ means "in the same directory". But which "same directory"? You would think it means "the same directory as the file including it", and most of the time you're right. Regardless, it does not mean the "root" directory of your site.
If the file was included by *another* file, the "same directory" could be different than you think. This often arises when you include libraries in other directories which themselves then include other files or try to open ini files, etc. etc.
$_SERVER[DOCUMENT_ROOT] is the absolute base directory of your site. It *never* hurts to include it as the start of a path, because it completely disambiguates the ".." and "." path issue.
Also, remember that PHP paths are file system paths on your server, NOT the same as the paths used (x)html, which are SITE-based.
Hope this didn't confuse things further!
the_pm
May 23rd, 2006, 21:28
Also, remember that PHP paths are file system paths on your server, NOT the same as the paths used (x)html, which are SITE-based.Meaning, if you didn't specify DOCUMENT_ROOT (which is quite safe and very handy), you would not use http://www.domain.com/ as your root for an absolute path, you would use something like /home/user/public_html/ as your root path.
sea otter
May 23rd, 2006, 21:31
Meaning, if you didn't specify DOCUMENT_ROOT (which is quite safe and very handy), you would not use http://www.domain.com/ as your root for an absolute path, you would use something like /home/user/public_html/ as your root path.
exactly right.
michaeljii
May 18th, 2011, 06:44
I found this is an informative and interesting post so i think so it is very useful and knowledgeable. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing ability has inspired me. Really the article is spreading its wings rapidly...
JN0-343 (http://www.examsheets.com/exam/JN0-343.htm)\350-029 (http://www.examsheets.com/exam/350-029.htm)\642-374 (http://www.examsheets.com/exam/642-374.htm)\70-291 (http://www.examsheets.com/exam/70-291.htm)\70-290 (http://www.examsheets.com/exam/70-290.htm)\PMI-002 (http://www.examsheets.com/exam/PMI-002.htm)\642-165 (http://www.examsheets.com/exam/642-165.htm)\642-642 (http://www.examsheets.com/exam/642-642.htm)
alton100
June 22nd, 2011, 06:49
Thanks for sharing this information. I really like your way of expressing the opinions and sharing the information. It is good to move as chance bring new things in life, paves the way for advancement, etc. But it is well known to everyone that moving to new location with bulk of goods is not an easy task to move or shift from one place to other place because I have experienced about that and I face the problem like that. There I go to village near to my city faced that problem there.
000-115 (http://www.certidea.eu/000-115-exam.html) \\ 70-652 (http://www.certidea.eu/70-652-exam.html) \\ 642-357 (http://www.certidea.eu/642-357-exam.html) \\ 70-685 (http://www.certidea.eu/70-685-exam.html) \\ 642-437 (http://www.certidea.eu/642-437-exam.html) \\ 70-513 (http://www.certidea.eu/70-513-exam.html) \\ 642-983 (http://www.certidea.eu/642-983-exam.html) \\ 352-001 (http://www.certidea.eu/352-001-exam.html) \\ JN0-101 (http://www.certidea.eu/JN0-101-exam.html) \\ 646-046 (http://www.certidea.eu/646-046-exam.html)
michaeljii
June 23rd, 2011, 12:39
I really like your way of expressing the opinions and sharing the information. It is good to move as chance bring new things in life, paves the way for advancement, etc. But it is well known to everyone that moving to new location with bulk of goods is not an easy task to move or shift from one place to other place because I have experienced about that and I face the problem like that. There I go to village near to my city faced that problem there.
_________________________
Hookah (http://www.southsmoke.com)
clark40
July 25th, 2011, 13:17
I am speechless. This is a fantastic site and very engaging too. Excellent work! That’s not really much coming from an amateur publisher like me, but it’s all I could think after enjoying your posts. Great grammar and vocabulary. Not like other site. You really know what you’re talking about too. So much that you made me want to explore more. Your blog has become a stepping stone for me, my friend. Thanks for the detailed journey. I really enjoyed the posts that I have read so far.70-511 (http://www.pass4sures.me/70-511-testking.html) | 70-512 (http://www.pass4sures.me/70-512-testking.html) | 70-513 (http://www.pass4sures.me/70-513-testking.html) | 70-513 (http://www.pass4sures.me/70-513-testking.html) | 70-515 (http://www.pass4sures.me/70-515-testking.html) | 70-516 (http://www.pass4sures.me/70-516-testking.html) \ 70-516 (http://www.pass4sures.me/70-516-testking.html) \ 70-519 (http://www.pass4sures.me/70-519-testking.html)
johnmartin
September 20th, 2011, 08:25
hi i have just joined
vBulletin® v3.6.8, Copyright ©2000-2012, Jelsoft Enterprises Ltd.