miércoles, 8 de junio de 2016
Moises SMS www.moises-sms.com, un nuevo servicio de envie de SMS a Cuba
Le invitamos a registrarse y prober el servicio, obtiene 5 sms gratuitos.
miércoles, 25 de julio de 2012
Detectar País, Región , Ciudad, Latitud , Zona horaria dado el IP de un cliente web. Código PHP
Una buena práctica en sitios web que necesiten registro de usuario es detectar el país y otros datos que pueden ser útiles aportando valor agregado y seguridad a su web .
¿Cómo detectar el IP real de un usuario que entra a su web?
Este código está en montones de páginas, lo comparto con ustedes en la clase que verán más adelante : método es getRealIP() de la clase IPLocalizador.
¿Cómo determinar dado el IP de un cliente , datos como: país , zona , ciudad , coordenadas , zona horaria?
Para ello podemos hacer uso de alguna API en internet que brinde el servicio gratis. Yo en este caso recomiendo usar el API que proporciona la web: www.ipinfodb.com
Paso 1: Registrarse en la web (http://www.ipinfodb.com/register.php) al registrarse y confirmar , obtienes una llave, esta llave no es más que un código que te identifica para hacer distintas consultas.
Ahora solo tenemos que hacer envíos al API de la siguiente manera:
http://api.ipinfodb.com/v3/ip-city/?key={llave}&ip={IP}
Como se puede ver en la URL anterior, se pasa de forma obligatoria key y ip. De forma opcional se pueden pasar los siguientes parámetros:
|
Parámetro
|
Valor
por defecto
|
Posibles
valores y significado
|
|
format
|
raw
|
raw => Formato texto separado
por punto y coma
xml => Formato XML
json => Formato json
|
De modo que usted llamando al método getData($ip,$key) de la clase IPLocalizador, puede obtener un objeto de la clase IPLocalizadorData , con toda la información que inicialmente deseábamos obtener.
Limitantes de la API
martes, 28 de junio de 2011
Copy directory folder PHP
Copy whole directory folder PHP
It is not exist any php function that allow make a copy of whole folder to another directory. The copy function not make it , only can a single file copy
below it show and explain some ways to do it.
function copyDirToDir($src,$dst){
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . DIRECTORY_SEPARATOR . $file) ) {
copyDirToDir($src . DIRECTORY_SEPARATOR . $file,$dst . DIRECTORY_SEPARATOR . $file);
}
else {
copy($src . DIRECTORY_SEPARATOR . $file,$dst . DIRECTORY_SEPARATOR . $file);
}
}
}
closedir($dir);
}
In this case the function copyDirToDir, receive as parameter a source direction and a destiny direction where it makes the copy
Pre-condition: 1- Both directories are valid , destiny direction is not need exist beacuse it will be create but the tree route until penultimate folder must be valid.
2- Must exist permissions in both directories for make copy and create files.
It makes a recursive search of the folders and copy all files.
Copy using command (shell_exec)
$src = "moises/home/public_html/folder";
$destiny = "moises/home/public_html/destiny ";shell_exec("cp -r $src $destiny");
Copy files by patterns
If we wants make a copy of all files with extensions (.php) in a folder, we can make use of the function copyPatternToDir see the way below:
function copyPatternToDir($pattern, $dir)
{
foreach (glob($pattern) as $file) {
if(!is_dir($file) && is_readable($file)) {
$dest = realpath($dir) .DIRECTORY_SEPARATOR. basename($file);
copy($file, $dest);
}
}
}