NYCPHP Meetup

NYPHP.org

[nycphp-talk] variable scope question

Jürgen Wind jwind at gmx.de
Sun Feb 4 19:34:18 EST 2007




mikesz at qualityadvantages.com wrote:
> 
> 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
> 
> 
> 
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 
> 
why don't just use $_SERVER['REMOTE_ADDR'] everywhere in your script?
it's a "superglobal".
-- 
View this message in context: http://www.nabble.com/variable-scope-question-tf3168397.html#a8799459
Sent from the NYPHP-Talk mailing list archive at Nabble.com.




More information about the talk mailing list