Rasekamon Posted February 16, 2011 Share Posted February 16, 2011 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). I know it has something to do with $_ENV and $_SERVER but... I would be thrilled for some guidance! Best regards, Rasekamon Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/ Share on other sites More sharing options...
Jessica Posted February 16, 2011 Share Posted February 16, 2011 Are you thinking like var_dump($_ENV)? Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/#findComment-1175109 Share on other sites More sharing options...
Rasekamon Posted February 16, 2011 Author Share Posted February 16, 2011 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".. Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/#findComment-1175116 Share on other sites More sharing options...
Jessica Posted February 16, 2011 Share Posted February 16, 2011 *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. Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/#findComment-1175118 Share on other sites More sharing options...
Pikachu2000 Posted February 16, 2011 Share Posted February 16, 2011 So by "task", you mean "homework", don't you? Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/#findComment-1175124 Share on other sites More sharing options...
Jessica Posted February 16, 2011 Share Posted February 16, 2011 So by "task", you mean "homework", don't you? I never realize this, since I never had a chance to take PHP in a class. I forget that some places will actually teach it Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/#findComment-1175126 Share on other sites More sharing options...
Rasekamon Posted February 16, 2011 Author Share Posted February 16, 2011 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 :-) Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/#findComment-1175139 Share on other sites More sharing options...
Pikachu2000 Posted February 16, 2011 Share Posted February 16, 2011 I'll give you the tools you'll need for this. See what you come up with using <pre> and print_r. Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/#findComment-1175141 Share on other sites More sharing options...
Rasekamon Posted February 16, 2011 Author Share Posted February 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/227896-how-do-i-print-all-environment-variables-with-names-and-values/#findComment-1175160 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.