public function createnewKey(Request $request) { $salt = hash('sha256', time() . mt_rand()); $new_key = substr($salt, 0, 40); $key = new key(); $key->key = $new_key; if ($key->save()) { return $this->httpCreate(); } }
public function show(Request $request) { // $url = $request->input('input_data'); $key = $this->getUniqueRandomKey(); if ($request->ajax()) { $data = new key(); $data->url = $url; $data->key = $key; $data->user_id = '1'; $data->ip = $request->getClientIp(); $data->save(); //checking the url repetition and if repeated then returning the old one if ($this->checkUrlRepetition($url)) { $repeated_key = DB::table('keys')->where('keys.url', '=', $url)->value('key'); $full_url = "http://ucut.in/" . $repeated_key; } else { $full_url = "http://ucut.in/" . $key; } return response()->json(['message' => 'created', 'url' => $full_url]); } }
/** * @depends testInterface * @return null */ public function testKeyIndexManyColumns() { $column = array('col1', 'col2'); $key = new key('my_index', $column); $this->assertEquals('my_index', $key->getIndexName()); $expected = "key my_index (col1,col2)"; $this->assertEquals($expected, $key->buildSql()); }
function page($page, $total, $phpfile, $pagesize = 3, $pagelen = 3, $key = '') { $pagecode = ''; //定义变量,存放分页生成的HTML $page = intval($page); //避免非数字页码 $total = intval($total); //保证总记录数值类型正确 if (!$total) { return array(); } //总记录数为零返回空数组 $pages = ceil($total / $pagesize); //计算总分页 //处理页码合法性 if ($page < 1) { $page = 1; } if ($page > $pages) { $page = $pages; } //计算查询偏移量 $offset = $pagesize * ($page - 1); //页码范围计算 $init = 1; //起始页码数 $max = $pages; //结束页码数 $pagelen = $pagelen % 2 ? $pagelen : $pagelen + 1; //页码个数 $pageoffset = ($pagelen - 1) / 2; //页码个数左右偏移量 //生成html $pagecode = '<div class="page">'; $pagecode .= "<span> {$page} / {$pages} </span>"; //第几页,共几页 //如果是第一页,则不显示第一页和上一页的连接 if ($page != 1) { $pagecode .= "<a href=do.php?" . key::GetEncrypt("{$phpfile}?key=" . $key . "page=1") . "> 第一页 </a>"; //第一页 $pagecode .= "<a href=do.php?" . key::GetEncrypt("{$phpfile}?key=" . $key . "page=" . ($page - 1)) . "> 上一页 </a>"; } //分页数大于页码个数时可以偏移 if ($pages > $pagelen) { //如果当前页小于等于左偏移 if ($page <= $pageoffset) { $init = 1; $max = $pagelen; } else { //如果当前页大于左偏移 //如果当前页码右偏移超出最大分页数 if ($page + $pageoffset >= $pages + 1) { $init = $pages - $pagelen + 1; } else { //左右偏移都存在时的计算 $init = $page - $pageoffset; $max = $page + $pageoffset; } } } //生成html for ($i = $init; $i <= $max; $i++) { if ($i == $page) { $pagecode .= '<span> ' . $i . ' </span>'; } else { $pagecode .= "<a href=do.php?" . key::GetEncrypt("{$phpfile}?key=" . $key . "&page={$i}") . "> {$i} </a>"; } } if ($page != $pages) { $pagecode .= "<a href=do.php?" . key::GetEncrypt("{$phpfile}?key=" . $key . "&page=" . ($page + 1)) . "> 下一页 </a>"; //下一页 $pagecode .= "<a href=do.php?" . key::GetEncrypt("{$phpfile}?key=" . $key . "&page={$pages}") . "> 最后一页 </a>"; //最后一页 } $pagecode .= '</div>'; return array('pagecode' => $pagecode, 'sqllimit' => ' limit ' . $offset . ',' . $pagesize); }