Jump to content

How do I print all environment variables (with names and values)?


Recommended Posts

I've googled a lot but still can't find much of a clue for how to do this (printing all environment variables in PHP that is). :shrug:

I know it has something to do with $_ENV and $_SERVER but...

 

I would be thrilled for some guidance!

 

Best regards,

Rasekamon

I'm not sure since I'm new to PHP. I have a "task" that requires me to print all the PHP environment variables with names and values, each on a separate lines.

It's supposed to be a "HTTP-serversides program"..

*sigh*

$_ENV is an array. So you can process it like any other array.

Write some code and we can help, but I won't do it for you. If you can't get started, either this is too complex a task for you, or you're not stating the problem clearly.

Haha, thanks for your answers. Yeah it's homework.. and I just watched your little youtube link of "don't be this kid!!".. I'm totally that kid.

 

But ok, I'll freshen up on my array-skillz and try to do some loop that prints it all. Hope it's the right way to go :-)

Ah interesting. <pre> makes it look tidy and print_r() prints all the elements of the array. Neat!

 

Though it seems the array $_ENV is empty but the $_SERVER is full of stuff (I printed both):

 

"Array

(

)

Array

(

    [HTTP_HOST] => 127.0.0.1

    [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13

    ... etc."

 

Thanks for your help. It's progress :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.