red_avatar Posted May 1, 2007 Share Posted May 1, 2007 I just started learning about php but in the tutorial, I came across a small script: echo "$REMOTE_ADDR"; When I create the file and upload it to my domain, it doesn't show anything. I called up a list of the superglobals using the phpinfo() command and REMOTE_ADDR is on it and shows my IP so why doesn't it work? I tried other superglobals and they don't show either. I also read somewhere that it changed to $_SERVER["REMOTE_ADDR"] in the new PHP version but that turned up an error. Can anyone help me? It sounds like something needs to be set up but I can't find what. Link to comment https://forums.phpfreaks.com/topic/49554-superglobals-dont-work/ Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 $_SERVER["REMOTE_ADDR"] should work fine in a default installation. $REMOTE_ADDR would have worked long ago when register globals where on by default. Link to comment https://forums.phpfreaks.com/topic/49554-superglobals-dont-work/#findComment-242904 Share on other sites More sharing options...
red_avatar Posted May 2, 2007 Author Share Posted May 2, 2007 $_SERVER["REMOTE_ADDR"] should work fine in a default installation. $REMOTE_ADDR would have worked long ago when register globals where on by default. Thanks I discovered the problem - it's stupid how all this is so hard to find using Google. Basically, you can not use $_SERVER["REMOTE_ADDR"] as part of an echo when using " ". So writing echo "Your IP is $_SERVER["REMOTE_ADDR"]" is going to give an error. But writing $ip = $_SERVER["REMOTE_ADDR"] echo "Your IP is $ip" works. Before, echo "Your IP is $REMOTE_ADDR" worked too. I wonder how many changes there's been in the past few years since I stopped learning php - I have a 5 year old php book so I guess it's useless now? I can't even get simple scripts running without getting errors. Link to comment https://forums.phpfreaks.com/topic/49554-superglobals-dont-work/#findComment-243288 Share on other sites More sharing options...
btherl Posted May 2, 2007 Share Posted May 2, 2007 You can use the "complex" syntax (which is actually simple): echo "Your IP is {$_SERVER["REMOTE_ADDR"]}"; Link to comment https://forums.phpfreaks.com/topic/49554-superglobals-dont-work/#findComment-243297 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.