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

Link to comment
Share on other sites

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.