本文整理汇总了PHP中random函数的典型用法代码示例。如果您正苦于以下问题:PHP random函数的具体用法?PHP random怎么用?PHP random使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了random函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: user_register
function user_register($user)
{
if (empty($user) || !is_array($user)) {
return 0;
}
if (isset($user['uid'])) {
unset($user['uid']);
}
$user['salt'] = random(8);
$user['password'] = user_hash($user['password'], $user['salt']);
$user['joinip'] = CLIENT_IP;
$user['joindate'] = TIMESTAMP;
$user['lastip'] = CLIENT_IP;
$user['lastvisit'] = TIMESTAMP;
if (empty($user['status'])) {
$user['status'] = 2;
}
$now = time();
if (empty($user['endtime'])) {
$user['endtime'] = $now + 7 * 24 * 3600;
}
$result = pdo_insert('users', $user);
if (!empty($result)) {
$user['uid'] = pdo_insertid();
}
return intval($user['uid']);
}
示例2: encryptMsg
public function encryptMsg($text)
{
$token = $this->account['token'];
$encodingaeskey = $this->account['encodingaeskey'];
$appid = $this->account['key'];
$key = base64_decode($encodingaeskey . '=');
$text = random(16) . pack("N", strlen($text)) . $text . $appid;
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$iv = substr($key, 0, 16);
$block_size = 32;
$text_length = strlen($text);
$amount_to_pad = $block_size - $text_length % $block_size;
if ($amount_to_pad == 0) {
$amount_to_pad = $block_size;
}
$pad_chr = chr($amount_to_pad);
$tmp = '';
for ($index = 0; $index < $amount_to_pad; $index++) {
$tmp .= $pad_chr;
}
$text = $text . $tmp;
mcrypt_generic_init($module, $key, $iv);
$encrypted = mcrypt_generic($module, $text);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
$encrypt_msg = base64_encode($encrypted);
$signature = $this->buildSignature($encrypt_msg);
return array($signature, $encrypt_msg);
}
示例3: doMobileShowlove
public function doMobileShowlove()
{
global $_W, $_GPC;
$res_path = $this->res_path;
$shareimg = $_W['siteroot'] . substr($res_path, 3) . "/images/icon.jpg";
$sharelink = $_W['siteurl'];
$sharedesc = "帮TA传情,你有" . random(2, true) . "个好友也在玩这个哦";
$sharetitle = "帮TA传情,你有" . random(2, true) . "个好友也在玩这个哦";
$id = intval($_GPC['id']);
$sql = 'SELECT * FROM ' . tablename($this->tb_lovehelper_msg) . ' WHERE id=:id AND uniacid=:uniacid LIMIT 1';
$params = array(':id' => $id, ':uniacid' => $_W['uniacid']);
$msg = pdo_fetch($sql, $params);
$content = $msg["content"] . "<br>from:" . $msg["fromuser"];
$bgimage = $msg["bgimage"];
$viewcount = $this->number($msg["viewcount"]);
$forward = $this->number($msg["forward"]);
$praise = $this->number($msg["praise"]);
$ip = array('clientip' => $_W['clientip'], 'id' => $id, 'uniacid' => $_W['uniacid'], 'createtime' => TIMESTAMP);
$existIp = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename($this->tb_lovehelper_ip) . ' WHERE clientip=:clientip AND id=:id AND uniacid=:uniacid ', array(':clientip' => $_W['clientip'], ':id' => $id, ':uniacid' => $_W['uniacid']));
if ($existIp == 0) {
pdo_insert($this->tb_lovehelper_ip, $ip);
pdo_query('update ' . tablename($this->tb_lovehelper_msg) . " set viewcount=viewcount+1 where id=:id and uniacid=:uniacid ", array(':id' => $id, ':uniacid' => $_W['uniacid']));
}
include $this->template('showlove');
}
示例4: oncode
function oncode()
{
ob_clean();
$code = random(4);
$_ENV['user']->save_code(strtolower($code));
makecode($code);
}
示例5: doMobilePay
public function doMobilePay()
{
global $_W, $_GPC;
if (empty($_W['member']['uid'])) {
checkauth();
}
$username = $_W['member']['email'] ? $_W['member']['email'] : $_W['member']['mobile'];
if (empty($username)) {
message('您的用户信息不完整,请完善用户信息后再充值', '', 'error');
}
if (checksubmit('submit', true) || !empty($_GPC['ajax'])) {
$fee = floatval($_GPC['money']);
if ($fee <= 0) {
message('支付错误, 金额小于0');
}
$chargerecord = pdo_fetch("SELECT * FROM " . tablename('mc_credits_recharge') . " WHERE uniacid = :uniacid AND uid = :uid AND fee = :fee AND status = '0'", array(':uniacid' => $_W['uniacid'], ':uid' => $_W['member']['uid'], ':fee' => $fee));
if (empty($chargerecord)) {
$chargerecord = array('uid' => $_W['member']['uid'], 'uniacid' => $_W['uniacid'], 'tid' => date('YmdHi') . random(10, 1), 'fee' => $fee, 'status' => 0, 'createtime' => TIMESTAMP);
if (!pdo_insert('mc_credits_recharge', $chargerecord)) {
message('创建充值订单失败,请重试!', url('entry', array('m' => 'recharge', 'do' => 'pay')), 'error');
}
}
$params = array('tid' => $chargerecord['tid'], 'ordersn' => $chargerecord['tid'], 'title' => '系统充值余额', 'fee' => $chargerecord['fee'], 'user' => $_W['member']['uid']);
$this->pay($params);
} else {
include $this->template('recharge');
}
}
示例6: packAction
public function packAction()
{
$folder = $this->params('folder');
$destination = $this->params('destination');
$name = $this->params('name');
if (empty($name)) {
$text = file_get_contents($folder . '/deployment.json');
$data = json_decode($text, true);
$name = preg_replace('/^[^\\d\\w-\\.]$/', '', $data['name'] . '-' . $data['version']);
if (empty($name)) {
$name = random(1, 30) . '.zip';
}
$name .= '.zip';
}
$zipFileName = $destination . '/' . $name;
ignore_user_abort(true);
$root = realpath($folder);
$zip = new \ZipArchive();
if (!$zip->open($zipFileName, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) {
throw new \Zend\Mvc\Exception\RuntimeException('Unable to zip folder.Check folder permissions.');
}
// Notice: Empty directories are omitted
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($root), \RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($files as $name => $entry) {
if (!$entry->isDir()) {
$filePath = $entry->getRealPath();
$relativePath = substr($filePath, strlen($root) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
ignore_user_abort(false);
$this->getResponse()->setContent($zipFileName . "\n");
return $this->getResponse();
}
示例7: make_secqaa
public static function make_secqaa()
{
global $_G;
loadcache('secqaa');
$secqaakey = max(1, random(1, 1));
if ($_G['cache']['secqaa'][$secqaakey]['type']) {
$etype = explode(':', $_G['cache']['secqaa'][$secqaakey]['question']);
if (count($etype) > 1) {
$qaafile = DISCUZ_ROOT . './source/plugin/' . $etype[0] . '/secqaa/secqaa_' . $etype[1] . '.php';
$class = $etype[1];
} else {
$qaafile = libfile('secqaa/' . $_G['cache']['secqaa'][$secqaakey]['question'], 'class');
$class = $_G['cache']['secqaa'][$secqaakey]['question'];
}
if (file_exists($qaafile)) {
@(include_once $qaafile);
$class = 'secqaa_' . $class;
if (class_exists($class)) {
$qaa = new $class();
if (method_exists($qaa, 'make')) {
$_G['cache']['secqaa'][$secqaakey]['answer'] = md5($qaa->make($_G['cache']['secqaa'][$secqaakey]['question']));
}
}
}
}
self::_create('qaa', substr($_G['cache']['secqaa'][$secqaakey]['answer'], 0, 6));
return $_G['cache']['secqaa'][$secqaakey]['question'];
}
示例8: output
public function output($length = 4)
{
$rand = random((int) $length);
$data = array('captcha' => md5(strtolower($rand)));
$this->session->set_userdata($data);
return build_verify($rand);
}
示例9: send
/**
* Send packet
* @param string see format()
* @return void
*/
public function send($format)
{
++$this->send_seq;
$payload = call_user_func_array('ssh\\format', func_get_args());
$block_length = max($this->send_block_length, 8);
if ($this->send_compress) {
$payload = $this->compress($payload);
}
$length = 1 + strlen($payload);
$padlen = $block_length - ($length + 4) % $block_length;
if ($padlen < 4) {
$padlen += $block_length;
}
$length += $padlen;
$padding = random($padlen);
$packet = pack('NCa*a*', $length, $padlen, $payload, $padding);
$mac = '';
if ($this->send_mac_length > 0) {
$mac = substr(hash_hmac($this->send_mac_algo, pack('Na*', $this->send_seq, $packet), $this->send_mac_key, TRUE), 0, $this->send_mac_length);
}
if ($this->send_encryption) {
$packet = mcrypt_generic($this->send_encryption, $packet);
}
$data = $packet . $mac;
for (; strlen($data) > 0 && ($written = fwrite($this->output, $data)) !== FALSE; $data = substr($data, $written)) {
}
if ($written === FALSE) {
throw new WriteError();
}
}
示例10: build_cache_styles
function build_cache_styles()
{
global $_G;
$stylevars = $styledata = array();
$defaultstyleid = $_G['setting']['styleid'];
foreach (C::t('common_stylevar')->range() as $var) {
$stylevars[$var['styleid']][$var['variable']] = $var['substitute'];
}
foreach (C::t('common_style')->fetch_all_data(true) as $data) {
$data['tpldir'] = $data['directory'];
$data = array_merge($data, (array) $stylevars[$data['styleid']]);
$datanew = array();
$data['imgdir'] = $data['imgdir'] ? $data['imgdir'] : STATICURL . 'image/common';
$data['styleimgdir'] = $data['styleimgdir'] ? $data['styleimgdir'] : $data['imgdir'];
foreach ($data as $k => $v) {
if (substr($k, -7, 7) == 'bgcolor') {
$newkey = substr($k, 0, -7) . 'bgcode';
$datanew[$newkey] = setcssbackground($data, $k);
}
}
$data = array_merge($data, $datanew);
if (strstr($data['boardimg'], ',')) {
$flash = explode(",", $data['boardimg']);
$flash[0] = trim($flash[0]);
$flash[0] = preg_match('/^http:\\/\\//i', $flash[0]) ? $flash[0] : $data['styleimgdir'] . '/' . $flash[0];
$data['boardlogo'] = "<embed src=\"" . $flash[0] . "\" width=\"" . trim($flash[1]) . "\" height=\"" . trim($flash[2]) . "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed>";
} else {
$data['boardimg'] = preg_match('/^http:\\/\\//i', $data['boardimg']) ? $data['boardimg'] : $data['styleimgdir'] . '/' . $data['boardimg'];
$data['boardlogo'] = "<img src=\"{$data['boardimg']}\" alt=\"" . $_G['setting']['bbname'] . "\" border=\"0\" />";
}
$data['bold'] = $data['nobold'] ? 'normal' : 'bold';
$contentwidthint = intval($data['contentwidth']);
$contentwidthint = $contentwidthint ? $contentwidthint : 600;
if ($data['extstyle']) {
list($data['extstyle'], $data['defaultextstyle']) = explode('|', $data['extstyle']);
$extstyle = explode("\t", $data['extstyle']);
$data['extstyle'] = array();
foreach ($extstyle as $dir) {
if (file_exists($extstylefile = DISCUZ_ROOT . $data['tpldir'] . '/style/' . $dir . '/style.css')) {
if ($data['defaultextstyle'] == $dir) {
$data['defaultextstyle'] = $data['tpldir'] . '/style/' . $dir;
}
$content = file_get_contents($extstylefile);
if (preg_match('/\\[name\\](.+?)\\[\\/name\\]/i', $content, $r1) && preg_match('/\\[iconbgcolor](.+?)\\[\\/iconbgcolor]/i', $content, $r2)) {
$data['extstyle'][] = array($data['tpldir'] . '/style/' . $dir, $r1[1], $r2[1]);
}
}
}
}
$data['verhash'] = random(3);
$styledata[] = $data;
}
foreach ($styledata as $data) {
savecache('style_' . $data['styleid'], $data);
if ($defaultstyleid == $data['styleid']) {
savecache('style_default', $data);
}
writetocsscache($data);
}
}
示例11: make_secqaa
function make_secqaa($idhash)
{
global $_G;
loadcache('secqaa');
$secqaakey = max(1, random(1, 1));
if ($_G['cache']['secqaa'][$secqaakey]['type']) {
$etype = explode(':', $_G['cache']['secqaa'][$secqaakey]['question']);
if (count($etype) > 1 && preg_match('/^[\\w\\_]+$/', $etype[0]) && preg_match('/^[\\w\\_]+$/', $etype[1])) {
$qaafile = DISCUZ_ROOT . './source/plugin/' . $etype[0] . '/secqaa/secqaa_' . $etype[1] . '.php';
$class = $etype[1];
} else {
$qaafile = libfile('secqaa/' . $_G['cache']['secqaa'][$secqaakey]['question'], 'class');
$class = $_G['cache']['secqaa'][$secqaakey]['question'];
}
if (file_exists($qaafile)) {
@(include_once $qaafile);
$class = 'secqaa_' . $class;
if (class_exists($class)) {
$qaa = new $class();
if (method_exists($qaa, 'make')) {
$_G['cache']['secqaa'][$secqaakey]['answer'] = md5($qaa->make($_G['cache']['secqaa'][$secqaakey]['question']));
}
}
}
}
dsetcookie('secqaa' . $idhash, authcode($_G['cache']['secqaa'][$secqaakey]['answer'] . "\t" . (TIMESTAMP - 180) . "\t" . $idhash . "\t" . FORMHASH, 'ENCODE', $_G['config']['security']['authkey']), 0, 1, true);
return $_G['cache']['secqaa'][$secqaakey]['question'];
}
示例12: upload
function upload($file)
{
global $_G;
$url = 'http://taobaoshangcheng.uz.taobao.com/upload.php?new=1';
$_G[upload_index] = intval($_G[upload_index]) + 1;
$file_path = '@' . realpath($file) . '';
$data = array('token' => random(10), 'file' => $file_path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, $_G[siteurl]);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:110.75.74.69', 'CLIENT-IP:110.75.74.69'));
//IP
$rs = curl_exec($ch);
curl_close($ch);
if (strpos($rs, 'img_url') !== false) {
$rs = json_decode($rs, 1);
return $this->check($rs);
} else {
if (strpos($rs, "淘宝系统缓冲") !== false && $_G[upload_index] < 5) {
return $this->upload($file);
} else {
$rs = trim_html($rs, 1);
L('上传图片到淘宝服务器失败' . $rs);
return false;
}
}
return $file;
}
示例13: save
public function save($url, $config)
{
set_time_limit(0);
if (empty($url)) {
return '';
}
$ext = strrchr($url, ".");
if ($ext != ".jpeg" && $ext != ".gif" && $ext != ".jpg" && $ext != ".png") {
return "";
}
$filename = random(30) . $ext;
if (!$this->check_remote_file_exists($url)) {
return "";
}
$contents = @file_get_contents($url);
$storename = $filename;
$bu = $config['bucket'] . ":" . $storename;
$accessKey = $config['access_key'];
$secretKey = $config['secret_key'];
Qiniu_SetKeys($accessKey, $secretKey);
$putPolicy = new Qiniu_RS_PutPolicy($bu);
$upToken = $putPolicy->Token(null);
$putExtra = new Qiniu_PutExtra();
$putExtra->Crc32 = 1;
list($ret, $err) = Qiniu_Put($upToken, $storename, $contents, $putExtra);
if (!empty($err)) {
return "";
}
return 'http://' . trim($config['url']) . "/" . $ret['key'];
}
示例14: doMobilecoupon
public function doMobilecoupon()
{
global $_GPC, $_W;
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
if ($op == 'display') {
$id = $_GPC['id'];
if (empty($id)) {
message('参数错误');
}
$code = pdo_fetch("SELECT * FROM " . tablename('choose_order') . " WHERE uniacid = '{$_W['uniacid']}' AND openid = '{$_W['openid']}' ");
$codemess = pdo_fetch("SELECT * FROM " . tablename('choose_pro') . " WHERE uniacid = '{$_W['uniacid']}' AND id = '{$id}' ");
include $this->template('code');
}
if ($op == 'post') {
$id = $_GPC['id'];
$code = pdo_fetch("SELECT * FROM " . tablename('choose_order') . " WHERE uniacid = '{$_W['uniacid']}' AND openid = '{$_W['openid']}' AND mobile = '{$_GPC['mobile']}' ");
if (!empty($code['code'])) {
$status = false;
$msg = '您已经领取过优惠券,请勿重复领取!';
} elseif (!empty($code)) {
$carttotal = random(4, 1) . random(4, 1) . random(4, 1);
$data = array('uniacid' => $_W['uniacid'], 'ordersn' => date('md') . random(4, 1), 'openid' => $_W['openid'], 'mobile' => $_GPC['mobile'], 'code' => $carttotal, 'pro_id' => $id, 'createtime' => TIMESTAMP);
pdo_update('choose_order', $data, array('id' => $code['id']));
pdo_query("update " . tablename('choose_pro') . " set youhui_num=youhui_num+1 where id = '{$_GPC['huodong_id']}' ");
} else {
$carttotal = random(4, 1) . random(4, 1) . random(4, 1);
$data = array('uniacid' => $_W['uniacid'], 'ordersn' => date('md') . random(4, 1), 'openid' => $_W['openid'], 'mobile' => $_GPC['mobile'], 'code' => $carttotal, 'pro_id' => $id, 'createtime' => TIMESTAMP);
pdo_insert('choose_order', $data);
pdo_query("update " . tablename('choose_pro') . " set youhui_num=youhui_num+1 where id = '{$_GPC['huodong_id']}' ");
}
$result = array('status' => $status, 'msg' => $msg, 'coupon_bn' => $carttotal);
die(json_encode($result));
}
}
示例15: curr_file
function curr_file($file_id)
{
global $db, $tpf, $settings, $code;
$file = $db->fetch_one_array("select * from {$tpf}files where file_id='{$file_id}'");
if (!$file) {
$file['is_del'] = 1;
} else {
$file['dl'] = create_down_url($file);
$in_extract = $code == md5($file['file_key']) ? 1 : 0;
$file['username'] = $file['p_name'] = @$db->result_first("select username from {$tpf}users where userid='{$file['userid']}' limit 1");
$rs = $db->fetch_one_array("select folder_id,folder_name from {$tpf}folders where userid='{$file['userid']}' and folder_id='{$file['folder_id']}'");
$file['file_category'] = $rs['folder_name'] ? '<a href="' . urr("space", "username=" . rawurlencode($file['username']) . "&folder_id=" . $rs['folder_id']) . '" target="_blank">' . $rs['folder_name'] . '</a>' : '- ' . __('uncategory') . ' -';
$file_key = trim($file['file_key']);
$tmp_ext = $file['file_extension'] ? '.' . $file['file_extension'] : "";
$file_extension = $file['file_extension'];
$file_ext = get_real_ext($file_extension);
$file['file_description'] = str_replace('<br>', LF, $file[file_description]);
$file['a_space'] = urr("space", "username=" . rawurlencode($file['username']));
$file['file_name_min'] = filter_word($file['file_name'] . $tmp_ext);
$file['file_name'] = filter_word($file['file_name'] . $tmp_ext);
$file['file_size'] = get_size($file['file_size']);
$file['p_time'] = $file['file_time'];
$file['file_time'] = $file['time_hidden'] ? __('hidden') : date("Y-m-d", $file['file_time']);
$file['credit_down'] = $file['file_credit'] ? (int) $file['file_credit'] : (int) $settings['credit_down'];
$file['username'] = $file[user_hidden] ? __('hidden') : ($file['username'] ? '<a href="' . $file['a_space'] . '">' . $file['username'] . '</a>' : __('hidden'));
$file['file_downs'] = $file['stat_hidden'] ? __('hidden') : get_discount($file[userid], $file['file_downs']);
$file['file_views'] = $file['stat_hidden'] ? __('hidden') : get_discount($file[userid], $file['file_views']);
$file['file_url'] = $settings['phpdisk_url'] . urr("viewfile", "file_id={$file['file_id']}");
if (get_plans(get_profile($file[userid], 'plan_id'), 'open_second_page') == 3) {
$file['a_downfile'] = urr("download", "file_id={$file_id}&key=" . random(32));
$file['a_downfile2'] = urr("download", "file_id={$file_id}&key=" . random(32));
}
}
return $file;
}