NYCPHP Meetup

NYPHP.org

[nycphp-talk] php script

Allen Shaw ashaw at polymerdb.org
Fri Feb 22 10:15:36 EST 2008


Radu Cirimpei wrote:
> I need the remote address first for  "now how", then for site 
> security, for my good information, and so on, never a bad behavior!
Hi Radu,

I didn't mean to question your motives -- sorry if it sounded that way.  
But you asked "what is the best to do?", and the answer is going to be 
"it depends on what your goals are." 

For example, you wrote:
> If I use 'getenv("REMOTE_ADDR") ' for return the IP
> address of the
> person visiting my site, what is the best to do? To
> save in a variable, like '$ip = getenv("REMOTE_ADDR");
Why store it in a variable?  This is probably not necessary unless you 
plan to access the value many times over the course of the script, in 
which case calling getenv() many times is a waste of processing power.
> , then insert it in a database(MySQL),
Why store it in the database?  If you want to access it again later, a 
database may be the best place to keep it, but you might also just as 
well keep it in a file somewhere.  Either way, if you don't store it 
somewhere on disk it will be gone later. 
> then take it
> with a sql query and write it in another place saw
> only by me?
I would expect the database is seen only by you.  If it's not, you may 
have trouble finding another place that is.  Either way, you probably 
don't need to write it to two places -- pick the best one and use that.
> <?php
> $ip = getenv("REMOTE_ADDR") ;
> ?> -where can I place this? From the begin of
> index.php?
That depends on the structure of your script.  I would recommend that 
you define that variable just before it's used, not necessarily at the 
top of your script.  Again, it totally depends on the logical flow of 
your scripts.

Feel free to add more detail -- I or someone else here may be able to 
give you more specific answers.

Best Luck,
Allen

-- 
Allen Shaw
slidePresenter (http://slides.sourceforge.net)




More information about the talk mailing list