Rodan Media Group | Fort Lauderdale | Website Development | Domain Development | Semantic Networks | Web 3.0 & 4.0 | Video & Audio Production
RODAN MEDIA GROUP BLOG
Powered by RodanBlog.com

→ BLOG HOME | CATEGORIES: DEV | DOMAINS | GENERAL | ICANN | LEGAL | PHP | SEO | SOCIAL | TECH


→ SPECIAL SECTION: CLICK FOR LATEST ON MICROSOFT'S DOMAIN NAME TAKEDOWN

 

Serve Self or Document Root
One of Those Noob PHP Issues That Is Easier to Resolve Than You Think
Written by Danny Pryor
Posted on Monday, July 26, 2010, 12:41:18 AM Eastern Time USA



It's well after midnight, and it's time to go to bed. We've put a new site online today, making for a total of three websites deployed in the past week. So, this wonderful little PHP issue comes up rather frequently because it's a common bug we create, that we then have to fix.

We are not infallible.

The issue at hand is that old programming trick used in PHP code, that designed to call images or address links or link external files. It's the old $_SERVER['WHAT_GOES_HERE'] issue. In some cases you'll call 'SITE_ROOT', and in other cases it's 'DOCUMENT_ROOT'. But when, exactly, does one use one or the other in one's code?

Excellent question, and here's the very simple answer: When linking a file, such as ANY include file, you would use the 'DOCUMENT_ROOT', because you are attaching a file that is relative to the document's root directory.

Ergo, <?php include ($_SERVER['DOCUMENT_ROOT']."/includefile.php"); ?>. Simple enough, right? Good.

However, if you are grabbing an image, or perhaps importing a file inside an "echo" statement, you must reference the 'SITE_ROOT', as this looks for the absolute path for the website, then crawls through the directory structure. Essentially, 'DOCUMENT_ROOT' is for code, and 'SITE_ROOT' is for HTML.

E.g.: <?php echo "<img src='".$_SERVER['SITE_ROOT']."/images/mypic.jpg"' border='0'>"; ?>

Of course, there is also the $_SERVER['PHP_SELF'] global, which is usually used when sending and receiving form data in redux, but that's another issue, entirely. Have a splendid evening, and feel free to ask questions. I may know an answer, here and there!

;-)



Visitor Comments On This Post
Comments are not moderated; however, we reserve the right to remove vulgar and slanderous comments.

No Comments

 


Add Your Comment Here Your Name:


Your Email (Will NOT be displayed):


Your Website:
http://

Your Reply to this Post:



We use reCaptcha to prevent spam. If you are human, you have nothing to worry about here!



|


MORE IN DEV

Serve Self or Document Root
Monday, July 26, 2010, 12:41:18 AM

A Required Moment to Rip A Registrar To Shreds
Saturday, July 17, 2010, 01:52:24 PM

CSS Cheat Sheet
Friday, June 4, 2010, 02:59:15 PM

Designs That Produce Clicks
Thursday, April 1, 2010, 12:50:15 PM

Developer? Joomla-er? Word Presser?
Tuesday, March 9, 2010, 01:56:54 AM

Semantic Networks Versus Semantic Web
Wednesday, February 24, 2010, 11:20:43 AM

WordPress, Joomla, and Front Page, OH MY!
Thursday, February 4, 2010, 09:12:29 AM

Newsletter Posts
- Early 2009 -

June 22: New Opportunities in an Era of Change

May 11: Lacking Finesse, Use Brute Force ...

April 6: Technology Shifts & Factors of Production

March 24: Flamenco of Worlds is Begun

March 12: Online Video: Yes. But Not .TV

March 2: Emails Secure From Subpoena?

February 23: Finding the Niche

February 21: The Open Directory Portal

February 18: Client Varieties

February 16: Cyber Squatting

February 14: Failure of Parking


Domain News & Info

Latest news of the domain name industry
Web development site recommended by Domaining.com


The Domain King


Rodan Media Home

 

© 2001 - 2010 | RODAN MEDIA GROUP CORP. | WEBSITES | DOMAINS | AUDIO | PROJECTS | BLOG | CONTACT | OUR HISTORY | HOME

WEB DESIGNERS IN FORT LAUDERDALE, FLORIDA USA | T: 954.561.0600 | F: 954.333.6345