Obtener IP del visitante de forma eficiente
En muchas ocasiones necesitamos obtener la IP del visitante para habilitarle según que acciones o simplemente para reconocerlo sin necesidad de que se tenga que registrar y logear para interactuar con la Web.
La siguiente función obtiene la IP del usuario de forma eficiente:
<?php
function getIP() {
if (isset($_SERVER)) {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
return $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
return $_SERVER['REMOTE_ADDR'];
}
} else {
if (isset($GLOBALS['HTTP_SERVER_VARS']['HTTP_X_FORWARDER_FOR'])) {
return $GLOBALS['HTTP_SERVER_VARS']['HTTP_X_FORWARDED_FOR'];
} else {
return $GLOBALS['HTTP_SERVER_VARS']['REMOTE_ADDR'];
}
}
}
?>
Autor
Escrito por Jose Aguilar - Director ejecutivo y tecnológico en JA Modules. Experto programador PrestaShop y Experto programador WordPress.
Y para aplicar este codigo a una tienda prestashop?
Es decir para que registre la ip de quien se registra en la tienda igual que el modulo :http://www.presto-changeo.com/es/prestashop-free-modules/44-order-ip-log.html , hace con los pedidos
… [Trackback]…
[…] Informations on that Topic: jose-aguilar.com/blog/obtener-ip-del-visitante/ […]…
I am very happy to read this. This is the kind of manual that needs to be given and not the accidental misinformation that’s at the other blogs. Appreciate your sharing this best doc.
Que tal Jose, excelente Blog. Te comento que este codigo en particular no es muy eficiente, ya que te muestra la IP privada. Por tanto, podes tener 100 personas al mismo tiempo en tu website con la misma IP y ninguna forma de diferenciarla.
Un buen punto seria tomar la IP privada y tambien la IP Publica (de esa forma hasta podrias diferencias a 2 personas dentro de una misma LAN que salen por la misma IP).
No es muy dificil obtener la IP Publica, asi que seria una buena opcion.
I have not checked in here for a while because I thought it was getting boring, but the last several posts are great quality so I guess I’ll add you back to my daily bloglist. You deserve it friend 🙂
Very interesting details you have mentioned, thanks for putting up.
I truly enjoy studying on this internet site , it has got superb blog posts.
Wonderful web site. Plenty of useful information here. I’m sending it to some buddies ans additionally sharing in delicious. And certainly, thank you for your sweat!
I would like to thnkx for the efforts you’ve put in writing this blog. I am hoping the same high-grade site post from you in the upcoming as well. In fact your creative writing skills has encouraged me to get my own web site now. Really the blogging is spreading its wings rapidly. Your write up is a great example of it.
I gotta bookmark this web site it seems very beneficial handy
Hello! I realize this is kind of off-topic but I had to ask. Does managing a well-established website like yours require a massive amount work? I’m completely new to running a blog but I do write in my journal everyday. I’d like to start a blog so I will be able to share my own experience and views online. Please let me know if you have any kind of recommendations or tips for new aspiring bloggers. Appreciate it!
I feel that is among the so much significant info for me. And i am happy studying your article. However want to commentary on some basic things, The web site style is perfect, the articles is in reality great :D. Excellent activity, cheers.
You got a very superb website, Gladiolus I found it through yahoo.