Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Wondering why getenv doesn't display anything on my browser

 
Greenhorn
Posts: 9
PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I just started learning about PHP, and I tried to enter the following in order to find my document root:

<? php
$test = getenv('DOCUMENT_ROOT');
echo $test."\n";
?>

I found the code in a YouTube video, and it worked fine in the video. However, when I enter it into my Atom text editor and display it in my browser, I get a completely blank page. Does anyone know why?
 
Sheriff
Posts: 3121
459
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Brenda Anne wrote:I found the code in a YouTube video, and it worked fine in the video.


Please share a link to the video.
 
B. Jonsson
Greenhorn
Posts: 9
PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ron! Thanks for your reply. The video is here:
 
Saloon Keeper
Posts: 22122
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unless it's different on your version of PHP, the actual value is $_SERVER['DOCUMENT_ROOT'], not in the environment.

It's also considered bad form for general application use, since it references web application resources via their filesystem names (brute force) and not the application server's resource location mechanisms.

I'm not sure of what sort of mayhem that approach can do in PHP, but in Java, accessing a web application resource via a filesystem name can be fatal, as technically, the web application is supposed to be contained within a single WAR file and therefore the application resources do not even have discrete filesystem paths. The only thing that saves most people who do that is that many webapp servers unzip ("explode") WAR files before use. But it's still bad practice.
 
B. Jonsson
Greenhorn
Posts: 9
PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Tim,

Thanks! That got me unstuck.
 
I knew that guy would be trouble! Thanks tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic