get ip in 4.2+

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

get ip in 4.2+

Post by Sevengraff »

i used to be able to use $REMOTE_ADDR, but what is the var in 4.2.1?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

either:

$_SERVER['REMOTE_ADDR'];

or

getenv('REMOTE_ADDR');
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

Code: Select all

echo $_SERVERї'REMOTE_ADDR'];
gets me the error:
Notice: Undefined index: REMOTE_ADDR in E:\web\sevengraff media\sys\tag\make_tag.php on line 22

and getenv('REMOTE_ADDR') did nothing. no error or anything, just nothing
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Is it the localhost trying to access it? Maybe it has a problem with that.

do this:

Code: Select all

<pre>
<? print_r($_SERVER); ?>
</pre>
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

I love the new $_VARIABLES ;)
Image Image
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

phice wrote:I love the new $_VARIABLES ;)
"It makes life so much easier..."
Image Image
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

Code: Select all

&lt;?php

print_r($_SERVER&#1111;'REMOTE_ADDR']);

?&gt;
same error as before, undefined index.
im also having problems passing variables using the POST method. i use

if (isset($_REQUEST['name'])) { $name = $_REQUEST['name']; }

to make it easier to use, when i try to use $name or $_REQUEST['name'], it says that they are undefined.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

try

$HTTP_SERVER_VARS ?
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

Code: Select all

&lt;?php

echo "$HTTP_SERVER_VARS";

?&gt;
returns

Array

of all the things it could echo out, it says "Array"?!?!?!
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

THAT IS A GOOD THING!

try doing this:

Code: Select all

<?
$array = array("1","2");
echo $array;
?>
okay, with that simple misconseption out of the way try:

Code: Select all

<?=$HTTP_SERVER_VARS&#1111;'REMOTE_ADDR'];?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Instead of:

Code: Select all

print_r($_SERVER&#1111;'REMOTE_ADDR']);
try

Code: Select all

echo '&lt;pre&gt;';
print_r($_SERVER);
echo '&lt;/pre&gt;';
as Hobgoblin did at one point say. This will allow you to see exactly what is in the $_SERVER array (if anything). Alternatively, you could try

Code: Select all

phpinfo();
which will show all variables that are set as well as the version number for PHP and all it's configuration settings. If you've got PHP 4.2.1 there's no reason why $HTTP_SERVER_VARS would work but not $_SERVER.

Mac
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

echo '<pre>';
print_r($_SERVER);
echo '</pre>';


i got:

Array
(
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[SCRIPT_FILENAME] => E:\\program files\\PHP\\php.exe
[PATH_TRANSLATED] => E:\\program files\\DzSoft\\PHP Editor\\php5.tmp
[SCRIPT_NAME] => /php5.tmp
[REQUEST_URI] => /php5.tmp
[SYSTEMROOT] => C:\\WINNT
[WINDIR] => C:\\WINNT
[REDIRECT_STATUS] => 0
[PHP_SELF] => /php5.tmp
[argv] => Array
(
)

[argc] => 0
)

none of witch seemed to be an IP address.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Why can't you use $REMOTE_ADDR?

Have you tried

Code: Select all

&lt;?php
print_r($HTTP_SERVER_VARS);
?&gt;
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

print_r($HTTP_SERVER_VARS); did the same as the other one i tried.
also, it wont reconize vars that i pass with a forum. i used the POST method, but on the page that is suppost to get them, it says they are undefined.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Takuma wrote:Why can't you use $REMOTE_ADDR?

Have you tried

Code: Select all

&lt;?php
print_r($HTTP_SERVER_VARS);
?&gt;
Please read the rest of the post, and use common sense.

Sevengraff: Can you get the REMOTE_ADDR on other pages? Did you try phpinfo? Would it be too much of a hassle to reinstall php?
Post Reply