Forum Moderators: coopster

Message Too Old, No Replies

Howto get REMOTE ADDR if register globals = Off

         

minibear

9:54 pm on Aug 16, 2008 (gmt 0)

10+ Year Member



I have a my.php script, it needs to included at the very PHP script my Vbulletin forum.

<IfModule mod_php5.c>
php_value auto_prepend_file "/my.php"
</IfModule>

but this script can't get _SERVER["REMOTE_ADDR"], only if i tun register_globals = On

Hier is a test script. It can get $_SERVER['REMOTE_ADDR'] unter register_globals = Off.
if i type in browser:

http://mysite.com/test.php

why ?

test script:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo '$ip';
?>

but if it run in schell

>php test.php

PHP Notice: Undefined index: REMOTE_ADDR in test.php on line 2

anyone knows, how to fix this problem.

eeek

9:58 pm on Aug 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



but if it run in schell

Ah...there is no remote address when you run in a shell. That's why it is undefined.

minibear

10:30 pm on Aug 16, 2008 (gmt 0)

10+ Year Member



you are right.
If i needs to includ my.php at the very PHP script my Vbulletin forum.
whichone should i use between
require_once('my.php');
and
<IfModule mod_php5.c>
php_value auto_prepend_file "/my.php"
</IfModule>

Which difference have them.

AlexK

11:55 pm on Aug 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



include(), require()
and the httpd-launched
auto_prepend_file
all work the same way:- they drop the contents of the referenced-file into your current file, just as if that file contained the code in the first place.

Therefore, it depends on how you call the original file:

  • Call it from a shell script: no
    $_SERVER['REMOTE_ADDR']
    variable.
  • Call it from a browser:
    $_SERVER['REMOTE_ADDR']
    variable supplied.