Undefined Index Issue - Error
Moderator: General Moderators
- JMichaels22
- Forum Newbie
- Posts: 5
- Joined: Mon Feb 13, 2006 10:14 am
- Location: Chicago Burbs, IL
Undefined Index Issue - Error
All,
I am trying to create the following short variable name:
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
When I try to do this I get the following error and im not too sure why:
Notice: Undefined index: DOCUMENT_ROOT in C:\Inetpub\wwwroot\processorder.php on line 68
All the tags are in place and correct and when I comment out that piece of code everything else will work. Any ideas on what I am missing, seems like I am missing something obvious, possibly PHP setup?
Thanks
I am trying to create the following short variable name:
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
When I try to do this I get the following error and im not too sure why:
Notice: Undefined index: DOCUMENT_ROOT in C:\Inetpub\wwwroot\processorder.php on line 68
All the tags are in place and correct and when I comment out that piece of code everything else will work. Any ideas on what I am missing, seems like I am missing something obvious, possibly PHP setup?
Thanks
I've never encountered this problem before but I'm gathering from the manual that this variable isn't always available. Here is a tip in the suggestions on how to make it your self:
Code: Select all
if(!isset($_SERVER["DOCUMENT_ROOT")){
$_SERVER["DOCUMENT_ROOT"]=substr($_SERVER['SCRIPT_FILENAME'] , 0 , -strlen($_SERVER['PHP_SELF'])+1 );
}- JMichaels22
- Forum Newbie
- Posts: 5
- Joined: Mon Feb 13, 2006 10:14 am
- Location: Chicago Burbs, IL
How does this code work?
What exactly does this piece of code do? I understand that isset is testing to see if the variable is empty, then if it is it sets the variable. What I dont get is the last part of this code, what is it doing?
Thanks for the replies and for being patient =)
-Jassen
Thanks for the replies and for being patient =)
-Jassen
- JMichaels22
- Forum Newbie
- Posts: 5
- Joined: Mon Feb 13, 2006 10:14 am
- Location: Chicago Burbs, IL
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
The if statement is checking to see if there is a value set for $_SERVER["DOCUMENT_ROOT"]. If there isn't one, then it makes one for you based on values from a few other $_SERVER vars.
Code: Select all
<?php
if(!isset($_SERVER["DOCUMENT_ROOT"])) {
// If $_SERVER["DOCUMENT_ROOT"] does not have a set value...
// make one using this scripts file name
$_SERVER["DOCUMENT_ROOT"]=substr($_SERVER['SCRIPT_FILENAME'] , 0 , -strlen($_SERVER['PHP_SELF'])+1 );
}
?>