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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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"]}"; Quote Link to comment 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.