NYCPHP Meetup

NYPHP.org

[nycphp-talk] variable scope question

mikesz at qualityadvantages.com mikesz at qualityadvantages.com
Sat Feb 3 20:56:06 EST 2007


Hello everyone,

I have a question about variable scope that I probably should know the 
answer to but it is a puzzle at the moment.

I have a packaged script that I work on that has this problem but I can 
simplify the question with an example.

I have a scipt routine that collects a user IP address from  
$_SERVER['REMOTE_ADDR']. If I have $ip = $_SERVER['REMOTE_ADDR']; 
defined in the script, no problem but if I put the definition in an 
include statement like "require_once" it has no value but if I put the 
definition in a function in the include file and call the function, it 
contains the user IP address. By the way, the mod I am doing is for 
tracking badguys activity on a client site so I can see what parts of 
the script they are trying to access. I am collecting a lot more than 
just the ip address but this is a simplified example.

In the case I am working on, the definitions are in a header file and 
the IP collector is at the top of all the pages of the script. I have 
other "hardcoded" values defined in the header file that work?

Any ideas on what my problem is? I have created a function in the header 
file as a work around but I am wondering why the simple definition does 
not get parsed or why some variables work and others do not?

If the answer is obvious and I just don't get it, I hope someone can 
enlighten me. Thanks in advance.

mikesz






More information about the talk mailing list