function handler_updateLoginInfo($redis, $channel, $msg) { helper_log("redis submsg: " . $msg); $pubMsg = json_decode($msg, true); $db = new DB(); $db->updateUser($pubMsg); }
public function update($data) { $db = new DB(); foreach ($data as $key => $value) { $db->updateInTable($value, 'worker', $key); } }
public function delete($data) { $db = new DB(); for ($i = 0; $i < count($data); $i++) { $db->delete($data[$i], 'style'); } }
function insert() { $dbc = new DB(); $dbc->connect(); $sql = "insert into registered_users(FullName,Username,Password,Email,Mobile,RegNo) values('{$this->name}','{$this->username}','{$this->password}','{$this->email}','{$this->mobile}','{$this->regNo}')"; $dbc->query($sql); }
function getTopFive($uid) { $db = new DB(); //Create an array of all companies in format [companyname => companyid] $sql = "SELECT company_id, Name FROM Companies"; $compresults = $db->execute($sql); $allcompanies = []; $compavg = []; while ($row = $compresults->fetch_assoc()) { $allcompanies[$row['Name']] = $row['company_id']; } //Find the user's priority selection $usrsql = "SELECT priority FROM People WHERE person_id = {$uid}"; $usrresults = $db->execute($usrsql); $usrresults = $usrresults->fetch_assoc(); $priority = $usrresults['priority']; //get the average rating of each company in the prioritized category and store in an array foreach ($allcompanies as $key => $value) { //hey guess what SQL can calculate column averages for you $avgsql = "SELECT AVG({$priority}) FROM Reviews WHERE company_id = {$value}"; $avgresults = $db->execute($avgsql); $avgresults = $avgresults->fetch_assoc(); $compavg[$key] = implode(".", $avgresults); } //sort finished array high to low and grab the top 5 arsort($compavg); $topfive = array_slice($compavg, 0, 5); return $topfive; }
function showCupones() { $database = new DB(); echo "\n <table class=\"table table-striped table-bordered bootstrap-datatable datatable\">\n <thead>\n\t\t\t<tr>\n <th> </th>\n\t\t\t <th>Cupon</th>\n\t\t\t <th>Compra Minima</th>\n\n\t\t\t <th>Tipo</th>\n\t\t\t <th>Opciones</th>\n\t\t\t</tr>\n\t\t\t</thead>\n\t\t\t<tbody>"; $query = "SELECT * from cupon,cupontipo\n where cupon.cupontipo_id=cupontipo.cupontipo_id"; $results = $database->get_results($query); $i = 0; foreach ($results as $row) { $i += 1; echo "<tr>\n\t\t\t <td align=right><font > {$i} </td>\n\t\t\t <td ><a href=\"/index.php?data=cupones&op=generados&bulk=" . $row['bulk'] . "\" >"; switch ($row['cupontipo_id']) { case 1: echo "\$ " . dinero($row['cantidad']) . " MX"; break; case 2: echo $row['cantidad'] . " %"; break; } echo "</b><a>\n\t\t\t </td>"; echo "<td><font >" . dinero($row['compra_minima']) . "</td>\n\n\t\t\t<td> <font >" . strtoupper($row['cupontipo']) . "</td>"; echo "<td><button class=\"btn-primary btn-setting hidden-print\" onclick=\"showData('myModal',\n 'view/cupones/cupones_agregar.inc.php',\n 'f=editar&cuid=" . $row['cupon_id'] . "')\">Editar</button>\n\n <button class=\"btn-info btn-setting hidden-print\" onclick=\"showData('myModal',\n 'view/cupones/cupones.php',\n 'f=generar&cuid=" . $row['cupon_id'] . "&cupon=" . $row['cupon'] . "&monto=" . $row['cantidad'] . "&compra_minima=" . $row['compra_minima'] . "')\">Generar</button></td>"; echo "</tr>"; } echo " </tbody>\n </table>"; }
/** * @desc Devuelve el nombre de un usuario * @param int $id * @return string */ function getNombreUsuario($id) { $db = new DB(); $sql = "SELECT CONCAT(nombres, ' ', apellidos) as nombre "; $sql .= "FROM usuarios WHERE id = '{$id}'"; return $db->queryUniqueValue($sql); }
function checkInstalled(DB $db, $config) { $db->Exec("CREATE TABLE IF NOT EXISTS `{$config['database']['prefix']}polls` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`question` text NOT NULL,`close_date` int(11) unsigned NOT NULL,`vote_repeating` smallint(5) unsigned NOT NULL,`cookie_expire` int(10) unsigned NOT NULL,`show_hide_results` smallint(5) unsigned NOT NULL,`order_results` tinyint(3) unsigned NOT NULL,`created` int(11) unsigned NOT NULL,`randomize_order` tinyint(1) unsigned NOT NULL,`closed` tinyint(1) unsigned NOT NULL,PRIMARY KEY (`id`))"); $db->Exec("CREATE TABLE IF NOT EXISTS `{$config['database']['prefix']}poll_answers` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`poll_id` int(10) unsigned NOT NULL,`answer` text NOT NULL,`sort_order` int(10) unsigned NOT NULL,`image` int(11) unsigned NOT NULL,PRIMARY KEY (`id`))"); $db->Exec("CREATE TABLE IF NOT EXISTS `{$config['database']['prefix']}poll_votes` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`poll_id` int(10) unsigned NOT NULL,`identifier` varchar(255) NOT NULL DEFAULT '',`voted_date` int(11) unsigned NOT NULL,`voted_ip` int(11) unsigned NOT NULL,`answer_id` int(11) unsigned NOT NULL,PRIMARY KEY (`id`))"); $db->Exec("CREATE TABLE IF NOT EXISTS `{$config['database']['prefix']}poll_images` (`id` int(11) unsigned NOT NULL AUTO_INCREMENT,`upload_path` varchar(100) NOT NULL DEFAULT '',PRIMARY KEY (`id`))"); }
public function Save() { if ($this->_POST) { $ID = _intval($this->_POST['ID'], true); $Data['Title'] = trim($this->_POST['Title']); $Data['Url'] = trim($this->_POST['Url']); $Data['Describe'] = trim($this->_POST['Describe']); $Data['DisplayOrder'] = _intval($this->_POST['DisplayOrder'], true); $Data['Property'] = _intval($this->_POST['Property'], true) ? 1 : 0; $Data['Status'] = _intval($this->_POST['Status'], true) ? 1 : 0; $Data['CategoryID'] = _intval($this->_POST['CategoryID'], true); if (!$ID) { $Data['Created'] = date('Y-m-d H:i:s', $this->timestamp); $Data['CreatedUserID'] = $this->UserID; } else { $Data['Modified'] = date('Y-m-d H:i:s', $this->timestamp); $Data['ModifiedUserID'] = $this->UserID; } $DB = new DB(); if ($ID) { if ($DB->UpdateArray('tbl_links', $Data, array('ID' => $ID))) { $this->__Message('修改友情链接成功!', UrlRewriteSimple('Links', 'Index', true), '继续操作'); } else { $this->__Message('修改友情链接失败,请再一次尝试!'); } } else { if ($DB->insertArray('tbl_links', $Data)) { $this->__Message('添加友情链接成功!', UrlRewriteSimple('Links', 'Index', true), '继续操作'); } else { $this->__Message('添加友情链接失败,请再一次尝试!'); } } } }
function queryDB($args, $query, $bindings = null) { $results = []; try { $DB = new DB(); $offset = 0; $limit = 25; if (isset($args["offset"])) { $offset = abs(intval($args["offset"])); } if (isset($args["limit"])) { $limit = abs(intval($args["limit"])); } if (strpos($query, 'select') !== false) { $query .= " limit " . $limit . " offset " . $offset; } $query .= ";"; $queryOut = $DB->query($query, $bindings); $results["data"] = $queryOut; $results["meta"]["ok"] = true; $results["debug"]["offset"] = $offset; $results["debug"]["limit"] = $limit; $results["debug"]["count"] = count($queryOut); } catch (Exception $e) { error_log($e); $results["meta"]["ok"] = false; $results["debug"]["dbException"] = $e->getMessage(); } $results["debug"]["query"] = $query; $results["debug"]["bindings"] = $bindings; return $results; }
function mostrar_transacciones($fecha_inicio, $fecha_fin, $user) { $database = new DB(); //$fecha=fechaplusweek($fecha); $total_pagos = ceil($total / $abono); echo "\n\n\t\t\t\t\t<div>\n\t\t\t\t\t\t<table class=\"table table-condensed striped\" width=100% >\n\t\t\t\t\t\t\t <thead>\n\t\t\t\t\t\t\t\t <tr>\n\t\t\t\t\t\t\t\t\t <th style='text-align:right'>Id</th>\n\t\t\t\t\t\t\t\t\t <th style='text-align:center'>Fecha</th>\n\t\t\t\t\t\t\t\t\t <th style='text-align:center'>Movimiento</th>\n\t\t\t\t\t\t\t\t\t <th style='text-align:center'>Total</th>\n\t\t\t\t\t\t\t\t\t <th style='text-align:center'>Cliente</th>\n\t\t\t\t\t\t\t\t </tr>\n\t\t\t\t\t\t\t </thead>\n\t\t\t\t\t\t\t <tbody>"; $fecha_inicio_bd = $fecha_inicio; $fecha_fin_bd = $fecha_fin; $query = "SELECT * from movimiento,tipomov,admin,cliente\n\t\twhere movimiento.tipomov_id=tipomov.tipomov_id AND movimiento.admin_id=admin.admin_id AND (movimiento.tipomov_id=1 OR movimiento.tipomov_id=13 or movimiento.tipomov_id=14)\n AND movimiento.cliente_id=cliente.cliente_id AND cliente.empresa_id=0"; if ($fecha_inicio) { $query .= " AND fecha>='{$fecha_inicio_bd}' AND fecha<='{$fecha_fin_bd} 23:59:59' "; } if ($user) { $query .= " AND movimiento.admin_id={$user} "; } $query .= " ORDER BY fecha DESC"; $results = $database->get_results($query); foreach ($results as $item) { $vendedor = $item['nombre'] . " " . $item['apellidop']; echo "<tr><td style='text-align:right' width=30 >" . $item['movimiento_id'] . "</td>\n\t\t\t\t\t\t<td style='text-align:center'><span class='hidden-desktop'>" . fechamysqltous($item['fecha']) . "</span><a class='hidden-print' href=/index.php?data=estadisticas&op=ventas&fi=" . fechamysqltous($fecha_inicio) . "&hi={$hi}&ff=" . fechamysqltous($fecha_fin) . "&hf={$hf}&fid=" . $item['factura_id'] . ">" . fechamysqltomx($item['fecha'], "letra") . "</a></td>\n\t\t\t\t\t\t\t<td style='text-align:center'>" . $item['tipomov'] . "\n\t\t\t\t\t\t\t<br></td>\n\t\t\t\t\t\t\t<td style='text-align:right'>\$ " . dinero($item['cantidad'] + $item['iva']) . "</td>\n\t\t\t\t\t\t\t<td style='text-align:right'>" . $vendedor; echo " </td></tr>"; $n++; } echo " </tbody>\n\t\t</table> "; //echo "Pagos Atrazados: ".$pagos_atrazados; echo "</div>"; }
public function results() { $this->queryBuilder(); $db = new DB(); $this->results = $db->query($this->sql_builder)->fetch_all()->resultArray; return $this->results; }
public function testInstall() { global $DB; $query = "SHOW FULL TABLES WHERE TABLE_TYPE LIKE 'VIEW'"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $DB->query("DROP VIEW " . $data[0]); } $query = "SHOW TABLES"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $DB->query("DROP TABLE " . $data[0]); } include_once GLPI_ROOT . "/inc/dbmysql.class.php"; include_once GLPI_CONFIG_DIR . "/config_db.php"; // Install a fresh 0.80.5 DB $DB = new DB(); $res = $DB->runFile(GLPI_ROOT . "/install/mysql/glpi-0.80.3-empty.sql"); $this->assertTrue($res, "Fail: SQL Error during install"); // update default language $query = "UPDATE `glpi_configs`\n SET `language` = 'en_GB'"; $this->assertTrue($DB->query($query), "Fail: can't set default language"); $query = "UPDATE `glpi_users`\n SET `language` = 'en_GB'"; $this->assertTrue($DB->query($query), "Fail: can't set users language"); $GLPIlog = new GLPIlogs(); $GLPIlog->testSQLlogs(); $GLPIlog->testPHPlogs(); }
public function login($login, $pass) { //echo "construct " . $this->name[0]; if (!isset($_COOKIE['auth'])) { $db = new DB(); $sql = "SELECT *\n FROM users\n WHERE username = '******'"; $result = $db->query($sql); if ($row = $db->fetch_array($result)) { if ($row['password'] == md5($pass)) { $this->name = $login; $this->id = $row['id']; setcookie('user_id', $row['id']); setcookie('auth', md5(time())); setcookie('name', $this->name); } else { die('error login'); } } else { die('login error'); } } else { $this->name = $_COOKIE['name']; $this->id = $_COOKIE['user_id']; } return $this->name; }
public function updateMovie($uid, $imdbid, $catid = array()) { $db = new DB(); $catid = !empty($catid) ? $db->escapeString(implode('|', $catid)) : "null"; $sql = sprintf("update usermovies set categoryID = %s where userID = %d and imdbID = %d", $catid, $uid, $imdbid); $db->query($sql); }
function insert() { $db = new DB(); $db->connect(); $sql = "insert into contact(Username,Comments) values('{$this->username}','{$this->comments}')"; $db->query($sql); }
function get_thumb($id_imagen, $height, $width) { $cnx = new DB(); $sql = "SELECT vin_imagen FROM vinculacion WHERE vin_id='" . $id_imagen . "'"; $registro = $cnx->get_registro($sql); $image_path = "../../sistema/images/vinculacion/" . $registro->vin_imagen; //debug($image_path);exit(); // $image_path = "../../sistema/images/vinculacion/1.png"; /* $arreglo = array("images","no_disponible.jpg");//Si el archivo no existe if(file_exists("../".$imagen)) { $arreglo = explode("/",$imagen); } else { $imagen = implode ("/",$arreglo); } */ $images = new Imagenes(); $images->set_height($height); $images->set_width($width); $images->set_path_file($image_path); return $images->get_thumb(); }
public function login($POST) { $db = new DB(); $user = new User(); $user->setEmail($POST["email"]); $user->setPassword($POST["password"]); if ($user->getEmail() == "") { $response["status"] = 1; $response["msg"] = "กรุณากรอก Email"; } else { if ($user->getPassword() == "") { $response["status"] = 2; $response["msg"] = "กรุณากรอก Password"; } else { $array = array("email" => array("type" => $user->getDataType("email"), "value" => $user->getEmail()), array("type" => $user->getDataType("password"), "value" => $user->getPassword())); $sql = "SELECT * FROM users WHERE email = ? AND password = ?"; $data = $db->query($sql, $array); if (count($data) > 0) { $response["status"] = 0; $response["msg"] = "Success"; } else { $response["status"] = -1; $response["msg"] = "ไม่พบ Email/Password นี้ในระบบ"; } } } echo json_encode($response); }
public function save($isNewUser = false) { //create a new database object. $db = new DB(); $username = mysql_real_escape_string($this->username); $email = mysql_real_escape_string($this->email); $firstName = mysql_real_escape_string($this->firstName); $lastName = mysql_real_escape_string($this->lastName); $link = mysql_real_escape_string($this->link); $blog = mysql_real_escape_string($this->blog); //if the user is already registered and we're //just updating their info. if (!$isNewUser) { //set the data array $data = array("username" => "'{$username}'", "password" => "'{$this->hashedPassword}'", "email" => "'{$email}'", "firstName" => "'{$firstName}'", "lastName" => "'{$lastName}'", "link" => "'{$link}'", "blog" => "'{$blog}'"); //update the row in the database $db->update($data, 'users', 'id = ' . $this->id); } else { //if the user is being registered for the first time. $data = array("username" => "'{$username}'", "password" => "'{$this->hashedPassword}'", "email" => "'{$email}'", "link" => "'{$link}'", "blog" => "'{$blog}'", "firstName" => "'{$firstName}'", "lastName" => "'{$lastName}'", "join_date" => "'" . date("Y-m-d H:i:s", time()) . "'"); $this->id = $db->insert($data, 'users'); $this->joinDate = time(); } return true; }
function viewTransactions() { $db = new DB(); $stmt = $db->query("SELECT a.ID, a.amount, a.user_ID, b.name, a.type, c._type, a.date_trans, a.notes, \n\t\t\t\t\tCASE a.status\n\t\t\t\t\t\tWHEN 0 THEN 'On Process'\n\t\t\t\t\t\tWHEN 1 THEN 'Complete'\n\t\t\t\t\tEND as `status`\n\t\t\t\t\tFROM transactions AS a, users AS b, `user-meta` AS c\n\t\t\t\t\tWHERE a.user_ID = b.ID AND c.user_ID = b.ID AND a.user_ID = " . $_SESSION['user_ID'] . " ORDER BY a.ID DESC", array()); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); return empty($result) ? false : $result; }
function login() { $controller = new UserTools(); $db = new DB(); $db->connect(); if (!isset($_POST['apikey'])) { echo "bad api key"; return NULL; } if (isset($_POST['username']) && isset($_POST['password'])) { $user = $_POST['username']; $pass = $_POST['password']; $result = $controller->login($user, $pass); echo $result; /* $query = $db->select('users', 'username=$user,pass_hash=$pass'); if(mysql_num_rows($query) == 1){ //success $_SESSION['logged_in'] = $query['id']; } else { //fail echo "invalid username or password"; } */ } }
public function signin() { if ($this->get_request_method() != "POST") { $this->response('', 406); } $email = $this->_request['email']; $password = $this->_request['pwd']; $db = new DB(); $ultis = new Utils(); // Input validations if (!empty($email) and !empty($password)) { if (filter_var($email, FILTER_VALIDATE_EMAIL)) { $sql = "SELECT _uid, _email FROM users WHERE _email = '{$email}' AND _password = '******' LIMIT 1"; $rs = $db->query($sql); if ($rs->num_rows > 0) { // If success return authenticated key (sample) $result = array('access_token' => "633uq4t0qdtd1mdllnv2h1vs32"); $this->response($ultis->json($result), 200); } } } // If invalid inputs "Bad Request" status message and reason $error = array('status' => "Failed", "msg" => "Invalid Email address or Password"); $this->response($ultis->json($error), 400); }
public function delete_group($id) { $group = $this->get($id); $db = new DB(); $selector = array('id', '$id'); $db->delete($selector, ''); }
public function updateShow($uid, $tvinfoid, $catid = array()) { $db = new DB(); $catid = !empty($catid) ? $db->escapeString(implode('|', $catid)) : "null"; $sql = sprintf("update userseries set categoryID = %s where userID = %d and tvinfoID = %d", $catid, $uid, $tvinfoid); $db->exec($sql); }
public static function authentication() { // print_r($_SERVER); // exit(); if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="My Realm"'); header('HTTP/1.0 401 Unauthorized'); echo 'Text to send if user hits Cancel button'; exit; } else { $db = new DB(); $username = mysql_real_escape_string($_SERVER['PHP_AUTH_USER']); $password = mysql_real_escape_string($_SERVER['PHP_AUTH_PW']); $domain = 'nebula.com'; $hash = md5($username . ':' . $domain . ':' . $password); $sql = "SELECT id from n_nebulauser WHERE username='******' AND ha1='{$hash}'"; $q = $db->query($sql); if (mysql_num_rows($q)) { $fetch = mysql_fetch_assoc($q); return $fetch['id']; } else { return null; } } return false; }
public static function createPGPKey($username, $password) { // Can't create a pgp key without a name or a password. // Also, if they shouldn't have a whitespace in their name but if they do somehow it could be an exploit. if (empty($username) || empty($password)) { return false; } elseif (preg_match('/(\\s|\\n|\\r|\\/|\\.)/', $username) || preg_match('/\\s\\n\\r/', $password)) { trigger_error("{$username} attempted exploit! - PGP Key creation"); return false; } // Create batch script for user. // RSA Keys // 2048 bit file_put_contents("/tmp/{$username}", "Key-Type: default\n\t\t\tSubkey-Type: default\n\t\t\tName-Real: {$username}\n\t\t\tName-Comment: generated key for securechatty\n\t\t\tName-Email: noreply@securechatty.com\n\t\t\tExpire-Date: 0\n\t\t\tPassphrase: {$password}\n\t\t\t%pubring /tmp/{$username}.pub\n\t\t\t%secring /tmp/{$username}.sec\n\t\t\t%commit"); // Create the keys $file = escapeshellarg('/tmp/' . $username); exec("gpg2 --gen-key --batch {$file}"); // Retrieve the keys $publickey = file_get_contents("/tmp/{$username}.pub"); $privatekey = file_get_contents("/tmp/{$username}.sec"); // Remove all unneeded files. unlink("/tmp/{$username}"); unlink("/tmp/{$username}.pub"); unlink("/tmp/{$username}.sec"); if (empty($publickey) || empty($privatekey)) { trigger_error("Key generation failed for {$username}!"); return false; } $db = new DB(); $update = $db->prepare("UPDATE users SET\n\t\t\t\tpublickey = :publickey,\n\t\t\t\tprivatekey = :privatekey\n\t\t\t WHERE username = :username"); $update->execute(array(':publickey' => $publickey, ':privatekey' => $privatekey, ':username' => $username)); return true; }
function catalogo($tid, $i) { $database = new DB(); $query = "SELECT categoria_id,categoria FROM categoria\n\t\twhere 1 "; $results = $database->get_results($query); foreach ($results as $row) { echo "<tr ><td colspan=3>" . $row['categoria'] . " </td></tr>"; $query = "SELECT descuento from temporada where temporada_Id={$tid}"; list($descuento) = $database->get_row($query); $query = "SELECT subcategoria_id,subcategoria FROM subcategoria where categoria_id=" . $row['categoria_id']; $subs = $database->get_results($query); foreach ($subs as $sub) { $query = "SELECT count(producto_id) as productos FROM producto\n\t\t\t\t\twhere producto.temporada_id={$tid} AND subcategoria_id=" . $sub['subcategoria_id']; if ($i) { $query .= " AND producto.descuento={$descuento}"; } else { $query .= " AND producto.descuento<>{$descuento}"; } list($productos) = $database->get_row($query); if ($productos) { echo "<tr><td></td><td align=right>\n\t\t\t\t\t\t<a href=/index.php?data=catalogo&subcat=" . $sub['subcategoria_id'] . "&tid={$tid}>" . $sub['subcategoria'] . "</a>\n </td>\n\t\t\t\t\t\t<td>{$productos}</td></tr>"; } } } }
function add($req, $file) { $title = $req["title"]; $image = $file['image']; $img_path = ""; $msg = array(); //save uploaded image $dir = "upload/big-image"; if (!file_exists($dir)) { mkdir($dir, 0777); } $target_upload = "upload/big-image/" . basename($image["name"]); $img_path .= $target_upload; if (!move_uploaded_file($image["tmp_name"], $target_upload)) { $msg['file'] .= "Failed to save the uploaded image"; } else { $msg['file'] .= "Save the image file: {$target_upload}"; } $db = new DB(); $likes = rand(0, 500); $rst = $db->modify("insert into image values(null, '{$img_path}', '{$title}', '{$likes}')"); if ($rst) { $msg['db'] = "success"; } else { $msg["db"] = "failed"; } echo json_encode($msg, JSON_UNESCAPED_UNICODE); }
public function getLessonByNumber($lesson_number, $course_id) { $db = new DB(); $query = "SELECT * FROM lessons WHERE lesson_number='" . $lesson_number . "' AND course_id='" . $course_id . "'"; $date = $db->query($query); return $date[0]; }
public function GetIDS($Keywords, $Property) { if (!$Keywords) { return false; } if (is_array($Keywords)) { foreach ($Keywords as $string) { $sql_ext .= ($sql_ext ? ' or ' : '') . 'Keywords=\'' . $string . '\''; } } else { $sql_ext = 'Keywords=\'' . $Keywords . '\''; } $sql = 'SELECT ' . $Property . ' FROM tbl_keywords WHERE ' . $sql_ext; $DB = new DB(); $RS = $DB->Select($sql); if ($RS) { $tmpIDS = ''; foreach ($RS as $list) { if ($list[$Property]) { $tmpIDS .= ($tmpIDS ? ',' : '') . $list[$Property]; } } $tmpIDS = preg_replace('/(,{2,})/', ',', $tmpIDS); if (substr($tmpIDS, 0, 1) == ',') { $tmpIDS = substr($tmpIDS, 1); } if (substr($tmpIDS, -1) == ',') { $tmpIDS = substr($tmpIDS, 0, -1); } $IDS = explode(',', $tmpIDS); return implode(',', array_unique($IDS)); } return false; }