function ip2Location($ip) { $ipinfodb = new ipinfodb(); $ipinfodb->setKey($this->config->getConfigValue("EXTRAWATCH_IPINFODB_KEY")); $locations = $ipinfodb->getGeoLocation($ip); $ip = $city = $country = $countryCode = $latitude = $longitude = $referer = ""; if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { if ($field == self::LATITUDE) { $latitude = $val; } if ($field == self::LONGITUDE) { $longitude = $val; } if ($field == self::CITY) { $city = $val; } if ($field == self::COUNTRY_NAME) { $country = $val; } if ($field == self::COUNTRY_CODE) { $countryCode = $val; } } } $geolocation = array('ipAdress' => $ip, 'city' => $city, 'country' => $country, 'countryCode' => $countryCode, 'latitude' => $latitude, 'longitude' => $longitude, 'referer' => $referer); return $geolocation; }
private function get_user_location() { if (!@$_COOKIE["geolocation"]) { $ipinfodb = new ipinfodb(); $ipinfodb->setKey('9e399207f85522c328d415081c607f9f18563342bd38c4a014c95800b92fff8b'); $visitorGeolocation = $ipinfodb->getGeoLocation($_SERVER['REMOTE_ADDR']); if ($visitorGeolocation['Status'] == 'OK') { base64_encode(serialize($visitorGeolocation)); setcookie("geolocation", @$data, time() + 3600 * 24 * 7); } } else { $visitorGeolocation = unserialize(base64_decode($_COOKIE["geolocation"])); } return $visitorGeolocation; }
$double = $modx->getCount('feoDownload', array('path' => $curPath, 'ip' => $_SERVER['REMOTE_ADDR'], 'downloadedon:>' => $tenMinAgo)); if ($double <= 0) { $unique = $modx->getCount('feoDownload', array('path' => $curPath, 'ip' => $_SERVER['REMOTE_ADDR'])); /** @var feoDownload $dl */ $dl = $modx->newObject('feoDownload'); $dl->set('path', $curPath); $dl->set('ip', $_SERVER['REMOTE_ADDR']); $dl->set('downloadedon', strftime('%Y-%m-%d %H:%M:%S')); $dl->set('unique', $unique > 0 ? false : true); $dl->set('referer', $_SERVER['HTTP_REFERER']); $geoApiKey = $modx->getOption('filelister.ipinfodb_api_key', $scriptProperties, ''); if ($useGeolocation && !empty($geoApiKey)) { $modx->loadClass('geolocation.ipinfodb', $fileLister->config['modelPath'], true, true); $geo = new ipinfodb($modx); $geo->setKey($geoApiKey); $locations = $geo->getGeoLocation($_SERVER['REMOTE_ADDR']); $geolocation = array(); if (!empty($locations[0]) && is_array($locations[0])) { $gl = $locations[0]; $dl->set('geolocation', $gl); $dl->set('country', $gl['CountryCode']); $dl->set('region', $gl['RegionName']); $dl->set('city', $gl['City']); $dl->set('zip', $gl['ZipPostalCode']); } if ($modx->user->hasSessionContext($modx->context->get('key'))) { $dl->set('user', $modx->user->get('id')); } } $dl->save(); }
function registrarUsuario($arr) { //usr:UsuarioVO, foto:ByteArray, token:String,FBid:String, funcion:Function $person = $arr[0]; $pet = $person->mascota; $foto = $arr[1]; $fb = $arr[2]; // Facebook token + id /*** Comienzo a registrar al usuario ***/ $objConectar = new conexion(); $conexion = $objConectar->conectar(); $dividido = $person->cumple / 1000; $ip = $_SERVER['REMOTE_ADDR']; $ipinfodb = new ipinfodb(); $ipinfodb->setKey('149048918a5419cf857a642d6013c2455eadb3f95e7df8e77f0f859d620fbd93'); $locations = $ipinfodb->getGeoLocation($ip); if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { if ($field == "CountryName") { $pais = $val; } } } $sql = "INSERT INTO usuario (clave, nombre, login, password, correo, cumple, foto, Confirmado, fechaCreacion, ip, pais) VALUES(default,'" . utf8_decode($person->firstname) . "','" . utf8_decode($person->login) . "','" . utf8_decode($person->contrasenia) . "','" . utf8_decode($person->email) . "',DATE_ADD(FROM_UNIXTIME(0), INTERVAL " . $dividido . " SECOND),'" . $person->foto . "',1,(SELECT unix_timestamp(now())),'" . $ip . "','" . $pais . "');"; mysql_query($sql, $conexion) or die("/= ! " . $sql); $res = mysql_query("SELECT clave FROM usuario WHERE correo = '" . $person->email . "'", $conexion); if (mysql_num_rows($res) > 0) { $clave = mysql_result($res, 0, 0); } $person->clave = $clave; $person->id = $clave; mysql_query("INSERT INTO Dinero_usuarios VALUES(" . $clave . ", 20000 );", $conexion); /*** Termino de registrar al usuario ***/ /*** Inicio Agregando foto ***/ $bytearray = $foto["jpegstream"]; $imageData = $bytearray->data; $idimage = "usuario_" . $clave . ".png"; $sql = "UPDATE `usuario` SET `foto` = 'http://www.boomonsters.com/app/content/data/users/pic/" . $idimage . "' WHERE `clave` =" . $clave; $res = mysql_query($sql, $conexion); $dato2 = ($success = file_put_contents("../../app/content/data/users/pic/" . $idimage, $imageData)) ? $idimage : $success; /*** Termino Agregando foto ***/ /*** Inicio Agregando mascota ***/ $sql = "INSERT INTO mascotas (idEspecie, IDclave, nombre, color, fechaCreacion, iddueno, fechaEstado, higiene, cansancio, animo, hambre, salud, fechaAct_items) VALUES (" . $pet->idEspecie . ", NULL,'" . $pet->nombre . "', " . $pet->color . ", CURRENT_TIMESTAMP," . $clave . ", CURRENT_TIMESTAMP, '" . $pet->atributos_masc[$i++] . "', '" . $pet->atributos_masc[$i++] . "', '" . $pet->atributos_masc[$i++] . "', '" . $pet->atributos_masc[$i++] . "', '" . $pet->atributos_masc[$i++] . "',1)"; //return $sql; $res = mysql_query($sql, $conexion); $sql2 = "SELECT max(IDclave) mx FROM mascotas WHERE nombre = '" . $pet->nombre . "' and iddueno = " . $clave; $res = mysql_query($sql2, $conexion); $id = mysql_result($res, 0, 0); $arrMascota[0] = "idMascota"; $arrMascota[1] = $id; /*** Termino Agregando mascota ***/ /*** Inicio agregar datos facebook ***/ $tk = $fb[0]; $su = $fb[1]; $sql = "INSERT INTO sesiones_secretos_fb (booid,uid,auth_token) VALUES(" . $clave . ",'" . $su . "','" . $tk . "')"; $res = mysql_query($sql, $conexion); $objConectar->desconectar(); /*** Termino agregar datos facebook ***/ /* Creando arreglo para retornar */ $arrReturn = array(); $arrReturn[0] = $person; // $arrReturn[1] = $dato2; // Foto $arrReturn[2] = $arrMascota; // Mascota $arrReturn[3] = $res; /* Termino arreglo para retornar */ return $arrReturn; //true }
function registerPerson($person) { $objConectar = new conexion(); $conexion = $objConectar->conectar(); $dividido = $person->cumple / 1000; //DATE_ADD(FROM_UNIXTIME(0), INTERVAL -13391999 SECOND /* $geolocation2 = new geolocation(false); $geolocation2->setTimeout(2); $geolocation2->setIP($_SERVER['REMOTE_ADDR']); $locations = $geolocation2->getGeoLocation(); $ip = $locations[0]["Ip"]; $pais = $locations[0]["CountryName"]; return $ip; */ //<---- RIP $ip = $_SERVER['REMOTE_ADDR']; $ipinfodb = new ipinfodb(); $ipinfodb->setKey('149048918a5419cf857a642d6013c2455eadb3f95e7df8e77f0f859d620fbd93'); $locations = $ipinfodb->getGeoLocation($ip); if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { if ($field == "CountryName") { $pais = $val; } } } // > //mysql_query( "insert into usuario (clave, nombre, login, password, correo, cumple, foto, Confirmado, fechaCreacion, ip, pais) values(default,'".utf8_decode($person->firstname)."','".utf8_decode($person->login)."','".utf8_decode($person->contrasenia)."','".utf8_decode($person->email)."',DATE_ADD(FROM_UNIXTIME(0), INTERVAL ".$dividido." SECOND),'algo',default);",$conexion); $sql = "INSERT INTO usuario (clave, nombre, login, password, correo, cumple, foto, Confirmado, fechaCreacion, ip, pais) VALUES(default,'" . utf8_decode($person->firstname) . "','" . utf8_decode($person->login) . "','" . utf8_decode($person->contrasenia) . "','" . utf8_decode($person->email) . "',DATE_ADD(FROM_UNIXTIME(0), INTERVAL " . $dividido . " SECOND),'" . $person->foto . "',1,(SELECT unix_timestamp(now())),'" . $ip . "','" . $pais . "');"; mysql_query($sql, $conexion) or die("/= ! " . $sql); // mysql_query( "insert into usuario values(default,'".utf8_decode($person->firstname)."','".$person->login."','".$person->contrasenia."','".$person->email."',FROM_UNIXTIME(".$dividido."),'algo',default);",$conexion); $confirmacion = md5(date('r', time())); $res = mysql_query("SELECT clave FROM usuario WHERE correo = '" . $person->email . "'", $conexion); if (mysql_num_rows($res) > 0) { $clave = mysql_result($res, 0, 0); } mysql_query("INSERT INTO ConfirmacionTemporal VALUES('" . $confirmacion . "'," . $clave . ");", $conexion); mysql_query("INSERT INTO Dinero_usuarios VALUES(" . $clave . ", 1000 );", $conexion); /* $url_confirmacion = "http://www.boomonsters.com/testingSite/confirmar.php?uid=".$clave."&cid=".$confirmacion.""; $codigohtml = "<table width='100%'> <tr> <td bgcolor='#00CC33'> <h1><font color='#FFCC66'>BooMonsters</font></h1><font color='#FFFFFF'> <h2>Confirmación</h2></font></td></tr><tr><td bgcolor='#FFFFFF'> <h2>Hola ".utf8_decode($person->firstname).",</h2> <p>Gracias , Por favor haz click <a href='".$url_confirmacion."' target='_blank'>aquí</a> para confirmar tu Correo. Una vez que confirmes que es tu correo, podrás accesar a todos los beneficios de BooMonsters en tu aplicación de escritorio. Si el enlace anterior no es soportado por tu programa de correo, haz click en el siguiente link o copia y pega en tu navegador de Internet.</p> <p><a href='".$url_confirmacion."' target='_blank'>".$url_confirmacion."</a></p> <p>Gracias por adoptar a tu <strong>BooMonster!</strong></p> <p> </p> </td> </tr> <tr> <td><span class='style9'>--- Trebox Media</span> </td> </tr> </table>"; $email = $person->email; $asunto = 'Confirmacion BooMonsters'; // To send HTML mail, the Content-type header must be set $cabeceras = 'MIME-Version: 1.0' . "\r\n"; $cabeceras .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $cabeceras .= 'From: BooMonsters <*****@*****.**>' . "\r\n"; if(!mail($email,$asunto,$codigohtml,$cabeceras)) return "Tremendus error with a simple If"; */ $template = new TemplateCorreo_Confirmacion(); $template->setDatos($person, $clave, $confirmacion); //return "Atributos de los templates: ".$template->url_confirmacion." * ".$template->email." * "; $ctrlCorreo = new ControlCorreos(); $ctrlCorreo->enviarCorreo($template); $sql = "SELECT nombre, password, correo, cumple, foto FROM usuario"; $consulta = mysql_query($sql, $conexion); $str = ""; while ($fila = mysql_fetch_array($consulta)) { $str = $str . $fila[0] . "\n"; } mysql_close($conexion); // Here you would register the person information contained in the 'person' parameter, // probably adding it to a database before returning a success flag. // Instead, for demonstration purposes, we will modify the firstname property. // Notice that we are not using associative array access syntax e.g. person['firstname'] //$person->firstname = $person->firstname . "(Modified by PHP)"; // We can also call methods on our PHP object. // The following calls the incrementAge method to increment the instance's age property. //$person->incrementAge(); // Now, when we return the object, it will have two modified properties, 'firstname' and 'age'. // It will maintain its type in Flash. //return $person; //return utf8_encode($str); $person->clave = $clave; return $person; }
function registrarUsuarioFB($arr) { $objConectar = new conexion(); $conexion = $objConectar->conectar(); $pet = $arr[0]; $arrFB = $arr[1]; $sk = $arrFB[0]; $su = $arrFB[1]; $ss = $arrFB[2]; $rs = 1; //Facebook if ($arrFB[3]) { $rs = $arrFB[3]; } /* Primero debo insertar al usuario para generar su ID Después hacer una consulta y obtengo el ID Luego mascota o FB, da igual. Insertaré primero a la mascota */ $person = $this->usrGlb; $dividido = $person->cumple / 1000; /* $geolocation = new geolocation(false); $geolocation->setTimeout(2); $geolocation->setIP($_SERVER['REMOTE_ADDR']); $locations = $geolocation->getGeoLocation(); $ip = $locations[0]["Ip"]; $pais = $locations[0]["CountryName"]; */ $ip = $_SERVER['REMOTE_ADDR']; $ipinfodb = new ipinfodb(); $ipinfodb->setKey('149048918a5419cf857a642d6013c2455eadb3f95e7df8e77f0f859d620fbd93'); $locations = $ipinfodb->getGeoLocation($ip); if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { if ($field == "CountryName") { $pais = $val; } } } //$sql = "INSERT INTO usuario (clave, nombre, login, password, correo, cumple, foto, Confirmado) VALUES(default,'".utf8_decode($person->firstname)."','".utf8_decode($person->login)."','".utf8_decode($person->contrasenia)."','".utf8_decode($person->email)."',DATE_ADD(FROM_UNIXTIME(0), INTERVAL ".$dividido." SECOND),'".$person->foto."',1);"; $sql = "INSERT INTO usuario (clave, nombre, login, password, correo, cumple, foto, Confirmado, fechaCreacion, ip, pais) VALUES(default,'" . utf8_decode($person->firstname) . "','" . utf8_decode($person->login) . "','" . utf8_decode($person->contrasenia) . "','" . utf8_decode($person->email) . "',DATE_ADD(FROM_UNIXTIME(0), INTERVAL " . $dividido . " SECOND),'" . $person->foto . "',1,(SELECT unix_timestamp(now())),'" . $ip . "','" . $pais . "');"; mysql_query($sql, $conexion) or die("/= ! " . $sql); $sql = "SELECT * FROM usuario WHERE login = '******' LIMIT 0,1"; //return $sql; $res = mysql_query($sql, $conexion); $i = 0; if (mysql_num_rows($res) > 0) { //Inserto a la mascota $person = $this->getUsuario(mysql_fetch_array($res)); $sql = "INSERT INTO mascotas (idEspecie, IDclave, nombre, color, fechaCreacion, iddueno, fechaEstado, higiene, cansancio, animo, hambre, salud) VALUES (" . $pet->idEspecie . ", NULL,'" . $pet->nombre . "', " . $pet->color . ", CURRENT_TIMESTAMP," . $person->id . ", CURRENT_TIMESTAMP, '" . $pet->atributos_masc[$i++] . "', '" . $pet->atributos_masc[$i++] . "', '" . $pet->atributos_masc[$i++] . "', '" . $pet->atributos_masc[$i++] . "', '" . $pet->atributos_masc[$i++] . "')"; //return $sql; $res = mysql_query($sql, $conexion); // or die(mysql_error()."[".$sql."]"); //Inserto a sus datos de RS $sql = "INSERT INTO Dinero_usuarios VALUES(" . $person->id . ",1000)"; mysql_query($sql, $conexion); switch ($rs) { case 1: //FB $table = "sesiones_secretos_fb"; break; case 2: //TW $table = "tokens_secretos_tw"; break; } $sql = "INSERT INTO " . $table . " VALUES(" . $person->id . ",'" . $su . "','" . $sk . "','" . $ss . "')"; mysql_query($sql, $conexion); $sql = "INSERT INTO usuario_social VALUES(" . $rs . "," . $person->id . ",'" . $su . "')"; mysql_query($sql, $conexion); $sql = "SELECT IDclave FROM mascotas WHERE iddueno = " . $person->id; //return "mascota |".$sql; $res = mysql_query($sql, $conexion); $idMascota = mysql_result($res, 0, 0); $objConectar->desconectar(); //echo $locations[0]["Ip"]; //echo $locations[0]["CountryName"]; return $idMascota; } else { return "Un error"; } $usr = $this->getUsuario(mysql_fetch_array($res)); $objConectar->desconectar(); }
<?php include 'ipinfodb.class.php'; //Load the class $ipinfodb = new ipinfodb(); $ipinfodb->setKey('149048918a5419cf857a642d6013c2455eadb3f95e7df8e77f0f859d620fbd93'); //Get errors and locations $locations = $ipinfodb->getGeoLocation($_SERVER['REMOTE_ADDR']); //$errors = $ipinfodb->getErrors(); //Getting the result //echo "<p>\n"; //echo "<strong>First result</strong><br />\n"; if (!empty($locations) && is_array($locations)) { foreach ($locations as $field => $val) { //echo $field . ' : ' . $val . "<br />\n"; if ($field == "CountryName") { echo "El pais es:" . $val; } } } //echo "</p>\n"; /* //Show errors echo "<p>\n"; echo "<strong>Dump of all errors</strong><br />\n"; if (!empty($errors) && is_array($errors)) { foreach ($errors as $error) { echo var_dump($error) . "<br /><br />\n"; } } else { echo "No errors" . "<br />\n";