function checkArr($checkArr) { //检查对应类型,参数是数组 //KEY-VALUE形,类似$password => 'normaol'这样构造即可 if (!is_array($checkArr)) { return false; } $check_ok = true; while ($value = current($checkArr)) { $result = key($checkArr); if (!empty($result)) { $check_ok &= checkStr($value, $result); } next($checkArr); } reset($checkArr); return $check_ok; }
<?php header('Content-type: application/json; charset=utf-8'); date_default_timezone_set('PRC'); require_once './mysqlClass.php'; if (isset($_POST['newstitle']) && isset($_POST['newscontent']) && isset($_POST['headlines'])) { $newstitle = checkStr($_POST['newstitle']); $newscontent = checkStr($_POST['newscontent']); $headlines = checkStr($_POST['headlines']); $dataId = isset($_POST['dataId']) ? $_POST['dataId'] : ""; $newsimg = isset($_POST['newsimg']) ? $_POST['newsimg'] : ""; if (isset($_FILES['file'])) { foreach ($_FILES['file']['tmp_name'] as $key => $data) { move_uploaded_file($data, "upload/" . $_FILES["file"]["name"][$key]); $newsimg = $newsimg . "upload/" . $_FILES["file"]["name"][$key] . ","; } } if ($dataId == "") { $addtime = date("Y-m-d H:i:s"); $sql = "INSERT INTO `news` ( `newstitle`, `newsimg`, `newscontent`, `headlines`, `addtime`) VALUES ('" . $newstitle . "', '" . $newsimg . "', '" . $newscontent . "', '" . $headlines . "', '" . $addtime . "')"; } else { $sql = "UPDATE `news` SET `newstitle`='" . $newstitle . "',`newsimg`='" . $newsimg . "',`newscontent`='" . $newscontent . "',`headlines`='" . $headlines . "' WHERE `newsid` = " . $dataId . ""; } $result = $mysql->query($sql); echo json_encode($result); } else { if (isset($_POST['delete'])) { $sql = "DELETE FROM `news` WHERE `news`.`newsid` = " . $_POST['delete']; $result = $mysql->query($sql); echo json_encode($result); } else {
$title = str_replace("'", "\\'", $json->Title); $year = $json->Year; $audience = checkStr(str_replace("'", "\\'", $json->Rated), false); $release_date = checkStr($json->Released, false); $runtime = checkStr(str_replace(" min", "", $json->Runtime), false); $genre = '|' . str_replace(", ", "||", $json->Genre) . '|'; $plot = checkStr(str_replace("'", "\\'", $json->Plot), false); $country = checkStr(str_replace(", ", "||", str_replace("'", "\\'", $json->Country)), true); $languages = checkStr(str_replace("'", "\\'", str_replace(", ", "||", $json->Language)), true); $awards = checkStr(str_replace("'", "\\'", $json->Awards), false); $poster = checkStr($json->Poster, false); $metascore = checkStr($json->Metascore, false); $imdb_rating = checkStr($json->imdbRating, false); $imdb_votes = checkStr($json->imdbVotes, false); $tomato_meter = checkStr($json->tomatoMeter, false); $box_office = str_replace("'", "\\'", checkStr($json->BoxOffice, false)); $poster_path = ''; if ($poster != '') { file_put_contents("data/movies/" . $urlId . ".jpg", fopen($poster, 'r')); $poster_path = "/data/movies/" . $urlId . ".jpg"; } if ($release_date != '') { $release_date = date("Y-m-d", strtotime($release_date)); } //DATA FROM IMDB foreach ($html->find('#pagecontent') as $tag) { $original_title = trim(str_replace("'", "\\'", $tag->find('h1.header span', 0)->plaintext), ' '); if ($title == $original_title) { $original_title = ""; } if ($country == '') {
/** * 检查手机号是否可用 * @return int 可用返回 1 其余返回0 */ function check_phone_can_use() { if (!isset($_POST['phone'])) { return 0; } else { $phone = $_POST['phone']; } if (is_null($phone) || $phone == '') { return 1; } if (!checkStr('phone', $phone)) { return 1; } $userObj = new UserClass(); return boolean2Num(!$userObj->check_data($phone, 'phone')); }
$hits = array('ok' => 0, 'notfound' => 0, 'error' => 0, 'cantwrite' => 0, 'cantdelete' => 0); for ($counter = 0; $counter < 1000; $counter++) { // write $ok = $storage->write(rand(0, COUNT_FILES), randomStr(), array()); if ($ok === FALSE) { $hits['cantwrite']++; } // remove //$ok = $storage->remove(rand(0, COUNT_FILES)); //if (!$ok) $hits['cantdelete']++; // read $res = $storage->read(rand(0, COUNT_FILES)); // compare if ($res === NULL) { $hits['notfound']++; } elseif (checkStr($res)) { $hits['ok']++; } else { $hits['error']++; } } $time = Debug::timer(); echo "Results:\n"; Debug::dump($hits); // expected results are: // [ok] => 1000 // should be 1000. If unlink() is used, sum [ok] + [notfound] should be 1000 // [notfound] => 0 // means "file not found", should be 0 if delete() is not used // [error] => 0, // means "file contents is damaged", MUST be 0 // [cantwrite] => ?, // means "somebody else is writing this file" // [cantdelete] => 0 // means "delete() has timeout", should be 0 echo $hits['error'] == 0 ? 'PASSED' : 'NOT PASSED!';
public function deliver_privilege($uid_now, $uid_next) { if (!checkStr('digit', $uid_now) || !checkStr('digit', $uid_next)) { return false; } $query_str1 = "SELECT * FROM `cs_user` WHERE uid={$uid_now};"; $query_str2 = "SELECT * FROM `cs_user` WHERE uid={$uid_next};"; $result1 = $this->dbObj->query($query_str1); $result2 = $this->dbObj->query($query_str2); if ($result1->num_rows <= 0 || $result2->num_rows <= 0) { if (is_object($result1)) { $result1->close(); } if (is_object($result2)) { $result2->close(); } return false; } $row1 = $result1->fetch_assoc(); $row2 = $result2->fetch_assoc(); if ($row1['privilege'] != '1' || $row2['privilege'] != '0') { return false; } $query_str1 = "UPDATE `cs_user` SET privilege=0 WHERE uid={$uid_now};"; $query_str2 = "UPDATE `cs_user` SET privilege=1 WHERE uid={$uid_next};"; $this->dbObj->query($query_str1); $this->dbObj->query($query_str2); if (is_object($result1)) { $result1->close(); } if (is_object($result2)) { $result2->close(); } return true; }
/** * 通用分页列表数据集获取方法 * * 可以通过url参数传递where条件,例如: index.html?name=asdfasdfasdfddds * 可以通过url空值排序字段和方式,例如: index.html?_field=id&_order=asc * 可以通过url参数r指定每页数据条数,例如: index.html?r=5 * * @param sting|Model $model 模型名或模型实例 * @param array $where where查询条件(优先级: $where>$_REQUEST>模型设定) * @param array|string $order 排序条件,传入null时使用sql默认排序或模型属性(优先级最高); * 请求参数中如果指定了_order和_field则据此排序(优先级第二); * 否则使用$order参数(如果$order参数,且模型也没有设定过order,则取主键降序); * * @param boolean $field 单表模型用不到该参数,要用在多表join时为field()方法指定参数 * @param string $target 分页内容替换目标ID * @param string $page_id 分页外层div的id * @author 许智皓优化 加入多表联查,分组 * * @return array|false * 返回数据集 */ protected function lists2($model, $where = array(), $order = '', $field = true, $join = '', $group = '', $target = '', $page_id = '') { $REQUEST = (array) I('request.'); if (is_string($model)) { $model = M($model); } if ($order === null) { $order = NULL; } $total = 0; if (!checkStr($join) && !checkStr($group)) { $total = $model->where($where)->count(); } else { if (checkStr($join) && !checkStr($group)) { $total = $model->join($join)->where($where)->count(); } else { if (!checkStr($join) && checkStr($group)) { $total = $model->where($where)->count('distinct ' . $group . ''); } else { if (checkStr($join) && checkStr($group)) { $total = $model->join($join)->where($where)->count('distinct ' . $group . ''); } } } } // if(checkStr($join)){ // $total = $model->join($join)->where($where)->count(); // }else{ // $total = $model->where($where)->count(); // } if (isset($REQUEST['r'])) { $listRows = (int) $REQUEST['r']; } else { $listRows = C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10; } $config = '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'; $page = new \Think\Page($total, $listRows, $REQUEST); if (!(empty($target) || empty($page_id))) { $page = new \Think\Pageajax($total, $listRows, $REQUEST, $target, $page_id); $config = '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER% %ajax%'; } if ($total > $listRows) { $page->setConfig('theme', $config); } $p = $page->show(); $this->assign('_page', $p ? $p : ''); $this->assign('_total', $total); $options['limit'] = $page->firstRow . ',' . $page->listRows; $res = NULL; if (!checkStr($join) && !checkStr($group)) { $res = $model->field($field)->where($where)->order($order)->limit($page->firstRow, $page->listRows)->select(); } else { if (checkStr($join) && !checkStr($group)) { $res = $model->field($field)->join($join)->where($where)->order($order)->limit($page->firstRow, $page->listRows)->select(); } else { if (!checkStr($join) && checkStr($group)) { $res = $model->field($field)->group($group)->where($where)->order($order)->limit($page->firstRow, $page->listRows)->select(); } else { if (checkStr($join) && checkStr($group)) { $res = $model->field($field)->join($join)->group($group)->where($where)->order($order)->limit($page->firstRow, $page->listRows)->select(); } } } } // echo $model->getlastsql();exit; return $res; }
$year = $json->Year; $audience = checkStr($json->Rated, false); $release_date = checkStr($json->Released, false); $runtime = checkStr(str_replace(" min", "", $json->Runtime), false); $genre = '|' . str_replace(", ", "||", $json->Genre) . '|'; $plot = checkStr(str_replace("'", "\\'", $json->Plot), false); $country = checkStr(str_replace(", ", "||", $json->Country), true); $languages = checkStr(str_replace("'", "\\'", str_replace(", ", "||", $json->Language)), true); $awards = checkStr(str_replace("'", "\\'", $json->Awards), false); $poster = checkStr($json->Poster, false); $metascore = checkStr($json->Metascore, false); $imdb_rating = checkStr($json->imdbRating, false); $tomato_meter = checkStr($json->tomatoMeter, false); $box_office = checkStr($json->BoxOffice, false); $production = checkStr($json->Production, false); $website = checkStr($json->Website, false); $poster_path = ''; if ($poster != '') { file_put_contents("data/movies/" . $urlId . ".jpg", fopen($poster, 'r')); $poster_path = "/data/movies/" . $urlId . ".jpg"; } if ($release_date != '') { $release_date = date("Y-m-d", strtotime($release_date)); } //DATA FROM IMDB foreach ($html->find('#pagecontent') as $tag) { $original_title = trim(str_replace("'", "\\'", $tag->find('h1.header span', 0)->plaintext), ' '); if ($title == $original_title) { $original_title = ""; } if ($tag->find('a.title-trailer', 0) != '') {