Problem with $_SERVER['DOCUMENT_ROOT'] in FF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michaeru
Forum Commoner
Posts: 28
Joined: Sun Mar 07, 2010 5:22 pm

Problem with $_SERVER['DOCUMENT_ROOT'] in FF

Post by michaeru »

I have these:
PHP File

Code: Select all

 
 
<link type="text/css" rel="stylesheet" href="<?php echo $_SERVER['DOCUMENT_ROOT'] . '/folder/globalStyles.css' ?>" />
 
 
The above code as shown on the Firefox View Source:

Code: Select all

 
 
<link type="text/css" rel="stylesheet" href="C:/xampp/htdocs/folder/globalStyles.css" />
 
 
It does not use my CSS and if I click or go to the href of the link tag, Firefox displays this error:

Firefox doesn't know how to open this address, because the protocol (c) isn't associated with any program.

Another is this:

Code: Select all

 
 
header('Location: ' . $_SERVER['DOCUMENT_ROOT'] . '/folder/page.php');
 
 
It also does not redirect to the page.

Help resolve this.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Problem with $_SERVER['DOCUMENT_ROOT'] in FF

Post by Christopher »

You don't want to use $_SERVER['DOCUMENT_ROOT'] for URLs because it contains the filesystem path. Use $_SERVER[’SCRIPT_NAME’] or 'http://' . $_SERVER[’SERVER_NAME’] . $_SERVER[’SCRIPT_NAME’] instead. This is not a "Firefox problem."
(#10850)
michaeru
Forum Commoner
Posts: 28
Joined: Sun Mar 07, 2010 5:22 pm

Re: Problem with $_SERVER['DOCUMENT_ROOT'] in FF

Post by michaeru »

Oh, will try it out. Thanks.
Post Reply