Jump to content

Superglobals don't work?


red_avatar

Recommended Posts

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

$_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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.