Oh.
And I REALLY meant to type ...
<?php phpinfo(); >?
fingggggers slipped on the g.
Though ph ping fo sounds a LOT better!
<grin>
Richard.
Main Topics
Browse All TopicsI installed PHP and have the phpinfo() working just fine. I'm working with a text book example that writes orders to a text file and I'm getting this error:
PHP Notice: Undefined index: DOC_ROOT in c:\Inetpub\wwwroot\PHP_Stu
The code:
Line 8: $DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOC_ROO
Line 63: $fp = fopen("$DOCUMENT_ROOT/Orde
I and have setup:
In php.ini: doc_root = "c:/Inetpub/wwwroot/PHP_St
(This is the same root as my website (IIS5) too)
The orders.txt file is located:
C:\Inetpub\wwwroot\PHP_Stu
Orders.txt file has proper permissions too...
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Can you cut and paste the entire line showing the doc_root variable?
Is it ...
_SERVER["DOCUMENT_ROOT"]
Also, from the PHP Manual ...
doc_root string
PHP's "root directory" on the server. Only used if non-empty. If PHP is configured with safe mode, no files outside this directory are served. If PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root if you are running php as a CGI under any web server (other than IIS) The alternative is to use the cgi.force_redirect configuration below.
The following steps are optional.
Edit your new php.ini file. If you plan to use OmniHTTPd, do not follow the next step. Set the doc_root to point to your webservers document_root. For example:
doc_root = c:\inetpub // for IIS/PWS
doc_root = c:\apache\htdocs // for Apache
Choose which extensions you would like to load when PHP starts. See the section about Windows extensions, about how to set up one, and what is already built in. Note that on a new installation it is advisable to first get PHP working and tested without any extensions before enabling them in php.ini.
On PWS and IIS, you can set the browscap configuration setting to point to: c:\windows\system\inetsrv\
Installed as CGI binary
Possible attacks
Using PHP as a CGI binary is an option for setups that for some reason do not wish to integrate PHP as a module into server software (like Apache), or will use PHP with different kinds of CGI wrappers to create safe chroot and setuid environments for scripts. This setup usually involves installing executable PHP binary to the web server cgi-bin directory. CERT advisory CA-96.11 recommends against placing any interpreters into cgi-bin. Even if the PHP binary can be used as a standalone interpreter, PHP is designed to prevent the attacks this setup makes possible:
Accessing system files: http://my.host/cgi-bin/php
The query information in a url after the question mark (?) is passed as command line arguments to the interpreter by the CGI interface. Usually interpreters open and execute the file specified as the first argument on the command line.
When invoked as a CGI binary, PHP refuses to interpret the command line arguments.
Accessing any web document on server: http://my.host/cgi-bin/php
The path information part of the url after the PHP binary name, /secret/doc.html is conventionally used to specify the name of the file to be opened and interpreted by the CGI program. Usually some web server configuration directives (Apache: Action) are used to redirect requests to documents like http://my.host/secret/scri
In PHP, compile-time configuration option --enable-force-cgi-redirec
From this, the doc_root setting in the PHP ini file is NOT the one that you get from $_SERVER (or $HTTP_SERVER_VARS on older versions of PHP).
e.g.
On my system, doc_root is blank, but $_SERVER['DOCUMENT_ROOT'] is set.
NOTE: DOCUMENT_ROOT, not doc_root. Difference.
Richard.
If you are not sure what I mean ...
<?php
error_reporting(E_ALL);
echo "This is what you are trying to get from doc_root : {$_SERVER['doc_root']}\n";
echo "This is what you are trying to get from doc_root : {$HTTP_SERVER_VARS['DOC_RO
echo "This is what you are REALLY looking for : {$HTTP_SERVER_VARS['DOCUME
$_SERVER is for V4.1+ of PHP and is now the preferred method.
$HTTP_SERVER_VARS is the old method and may no longer exist in V5.
Richard.
doc_root is a variable defined in php.ini, I guess you cannot access it through the script.
you can access the $_SERVER['DOCUMENT_ROOT'] or $HTTP_SERVER_VARS['DOCUMEN
so that would work for you:
$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$fp = fopen("$DOCUMENT_ROOT/PHP_
in fact, you don't even need to know the DOCUMENT_ROOT.
"/PHP_Stuff/Orders/orders.
Ok, I see. I got some results now to report back.
I tried doing:
$fp = fopen("$DOCUMENT_ROOT/Orde
and
$fp = fopen("$DOCUMENT_ROOT/PHP_
with $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMEN
still got the error. So I just hardcoded the stupid path:
$fp = fopen("c:/Inetpub/wwwroot/
and I got it to write the order info to the file. :)
I'm still getting this msg though:
PHP Notice: Undefined index: DOCUMENT_ROOT in c:\Inetpub\wwwroot\PHP_Stu
Line 3 = DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMEN
???
If your Line3 in your code matches the one you posted, i got the error.
you forgot the $ :
Line 3 = $DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMEN
the result is that your $DOCUMENT_ROOT variable won't be defined.
Maybe you should just try to print your $DOCUMENT_ROOT out to see if it is set correctly:
$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMEN
echo $DOCUMENT_ROOT;
check also phpinfo() for the system variable.
(search for DOCUMENT_ROOT in the page printed out by phpinfo())
by the way, which version of php do you have?
Yeah, it was a cut&paste error - my code has:
$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMEN
When I echo the value with:
<?php
//create short variable name
$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMEN
?>
<html>
<head>
<title>Holly's Auto Parts - Customer Orders</title>
</head>
<body>
echo $DOCUMENT_ROOT;
<h1>Holly's Auto Parts</h1>
<h2>Customer Orders</h2>
I just see (literally):
echo $DOCUMENT_ROOT; on the webpage. :0
I don't have $DOCUMENT_ROOT in my phpinfo() - just DOC_ROOT as mentioned above. (?)
Can you cut and paste the ENTIRE page of results from phpinfo(); please.
You should NOT be looking in the PHP Core section (the first configuration part), but in the PHP Variables section (the last configuration part) for DOCUMENT_ROOT or whatever your server says the document root is.
DOCUMENT_ROOT is what Sambar Server and Apache call it. IIS may decide to call it something totally different. Why? Because Microsoft do not know how to spell C O M P A T I B I L I T Y. (And I had to check that twice otherwise the point would not be so important!).
Mine reads ...
_SERVER["DOCUMENT_ROOT"] /home/xxxxxxxx/public_html
So, $_SERVER['DOCUMENT_ROOT'] === '/home/xxxxxxxx/public_htm
Richard.
Here's my PHPINFO page archived at:
http://globalwm.net/exchan
Just to explain ...
$DOCUMENT_ROOT = substr($_SERVER['PATH_TRAN
The substr() function is going to return a part of $_SERVER['PATH_TRANSLATED'
The part starts at the beginning of the string (the 0 in the substr()) and stops x number of characters short.
x is the length of the $_SERVER['SCRIPT_NAME'] (I suppose you could also use $PHP_SELF). The * - 1 provides a negative length and this, to substr() means drop this number of letters from the end of the string.
NOTE the line at the end ...
$rest = substr("abcdef", 0, -1); // returns "abcde"
From the PHP manual.
substr
(PHP 3, PHP 4 )
substr -- Return part of a string
Description
string substr ( string string, int start [, int length])
substr() returns the portion of string specified by the start and length parameters.
If start is non-negative, the returned string will start at the start'th position in string, counting from zero. For instance, in the string 'abcdef', the character at position 0 is 'a', the character at position 2 is 'c', and so forth.
Example 1. Basic substr() usage
<?php
$rest = substr("abcdef", 1); // returns "bcdef"
$rest = substr("abcdef", 1, 3); // returns "bcd"
$rest = substr("abcdef", 0, 4); // returns "abcd"
$rest = substr("abcdef", 0, 8); // returns "abcdef"
// Accessing via curly braces is another option
$string = 'abcdef';
echo $string{0}; // returns a
echo $string{3}; // returns d
?>
If start is negative, the returned string will start at the start'th character from the end of string.
Example 2. Using a negative start
<?php
$rest = substr("abcdef", -1); // returns "f"
$rest = substr("abcdef", -2); // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
?>
If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string). If string is less than start characters long, FALSE will be returned.
If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes a position beyond this truncation, an empty string will be returned.
Example 3. Using a negative length
<?php
$rest = substr("abcdef", 0, -1); // returns "abcde"
$rest = substr("abcdef", 2, -1); // returns "cde"
$rest = substr("abcdef", 4, -4); // returns ""
$rest = substr("abcdef", -3, -1); // returns "de"
?>
This works on both NIX and WIN
http://".$_SERVER['SERVER_
just tips
:-)
www.vision.to
Business Accounts
Answer for Membership
by: RQuadlingPosted on 2003-04-22 at 02:51:35ID: 8372067
Try ...
']))
<?php phpingfo(); ?>
to see what variables are supplied by your server.
You will need to confirm that this variable is present.
e.g.
if (!isset($_SERVER['DOC_ROOT
{
// Use some other variable ...
}
else
{
$sDR = $_SERVER['DOC_ROOT'];
}
Richard.