Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

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?
 
Marshal
Posts: 3079
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: 22011
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.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic