本文整理汇总了PHP中randStr函数的典型用法代码示例。如果您正苦于以下问题:PHP randStr函数的具体用法?PHP randStr怎么用?PHP randStr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randStr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: security
function security()
{
$_SESSION['verify'] = strtolower(randStr(4));
loadLib('Image');
Image::verify($_SESSION['verify'], 50, 33);
//Image::security($_SESSION['verify'], 80, 35, 20, CORE_PATH.'font/t1.ttf');
}
示例2: generate
/**
* Generate and return a token, save it to session.
*
* @param string $key Name of the key.
*
* @return string
*/
public function generate($key = '')
{
$token = base64_encode(time() . sha1(md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'])) . randStr(255));
if (empty($_SESSION['CSRF_' . $key])) {
$_SESSION['CSRF_' . $key] = $token;
return $token;
} else {
return $_SESSION['CSRF_' . $key];
}
}
示例3: yanzhengmaAction
/**
**
**生成验证码
**/
function yanzhengmaAction()
{
//session_register('SafeCode');
$type = 'png';
$width = 50;
$height = 20;
//header("Content-type: image/".$type);
@ob_end_clean();
srand((double) microtime() * 1000000);
$randval = randStr(4, "");
if ($type != 'png' && function_exists('imagecreatetruecolor')) {
$im = @imagecreatetruecolor($width, $height);
} else {
$im = @imagecreate($width, $height);
}
$r = array(225, 211, 255, 223);
$g = array(225, 236, 237, 215);
$b = array(225, 236, 166, 125);
$key = rand(0, 3);
$backColor = ImageColorAllocate($im, $r[$key], $g[$key], $b[$key]);
//背景色(随机)
$borderColor = ImageColorAllocate($im, 0, 0, 0);
//边框色
$pointColor = ImageColorAllocate($im, 255, 170, 255);
//点颜色
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
//背景位置
@imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
//边框位置
$stringColor = ImageColorAllocate($im, 255, 51, 153);
for ($i = 0; $i <= 100; $i++) {
$pointX = rand(2, $width - 2);
$pointY = rand(2, $height - 2);
@imagesetpixel($im, $pointX, $pointY, $pointColor);
}
@imagestring($im, 5, 5, 3, $randval, $stringColor);
$ImageFun = 'Image' . $type;
$ImageFun($im);
@ImageDestroy($im);
$_SESSION['SafeCode'] = $randval;
//产生随机字符串
@flush();
@ob_flush();
exit;
}
示例4: hashFileSavePath
/**
* 散列存储
* @param $savePath - 本地保存的路径
* @param $fileName - 原始文件名
* @param $isHashSaving - 是否散列存储。
* @param $randomFileName - 是否生成随机的Hash文件名。
* @return array
**/
function hashFileSavePath($savePath, $fileName = '', $isHashSaving = true, $randomFileName = true)
{
$hashFileName = $randomFileName ? md5(randStr(20) . $fileName . getMicrotime() . uniqid()) : md5($fileName);
$fileSaveDir = $savePath;
$hashFilePath = '';
//是否散列存储。
if ($isHashSaving) {
$hashFilePath = substr($hashFileName, 0, 1) . DIRECTORY_SEPARATOR . substr($hashFileName, 1, 2);
$fileSaveDir = $savePath . DIRECTORY_SEPARATOR . $hashFilePath;
}
$fileInfo = array("file_path" => $hashFilePath, "file_name" => $hashFileName, "error" => 0);
if (!is_dir($fileSaveDir)) {
$result = mkdir($fileSaveDir, 0777, true);
if (!$result) {
$fileInfo["error"] = 1;
}
}
return $fileInfo;
}
示例5: writeinto
function writeinto($info)
{
$infoarr = json_decode($info, true);
$flag = new M('flag');
$count = $flag->find("openid='" . $infoarr['openid'] . "'", '*', 'count');
$sqlarr = array("nickname" => bin2hex($infoarr['nickname']), "avatar" => $infoarr['headimgurl'], "fakeid" => randStr(), "sex" => $infoarr['sex'], "fromtype" => 'weixin', "datetime" => time(), "flag" => "2");
if (isset($infoarr['shadyphone'])) {
$shady = new M('cj_shady');
$shadyarr = $shady->find("phone=" . $infoarr['shadyphone']);
if (empty($shadyarr)) {
$addarr = array('phone' => $infoarr['shadyphone'], 'shady' => $shadyarr['grade']);
$sqlarr = array_merge($sqlarr, $addarr);
}
}
if ($count) {
$savve = $flag->update("openid='" . $infoarr['openid'] . "'", $sqlarr);
}
if ($savve) {
echo "ok";
}
}
示例6: picUpload
public function picUpload()
{
$result = array();
if (count($_POST)) {
$result['post'] = $_POST;
}
if (count($_FILES)) {
$result['files'] = $_FILES;
}
// Validation
$error = false;
if (!isset($_FILES['Filedata']) || !is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
$error = 'Invalid Upload';
exit;
}
// Processing start
$photo = $_FILES['Filedata'];
$time = SYS_TIME;
$year = date('Y', $time);
$month = date('m', $time);
$day = date('d', $time);
$pathInfo = upFileFolders($time);
$dstFolder = $pathInfo['path'];
$rand = randStr(4);
$dstFile = $dstFolder . $time . $rand . $photo['name'];
//the size of file uploaded must under 1M
if ($photo['size'] > 3000000) {
$error = '图片太大不能超过3M';
exit;
}
//save the temporary file
@move_uploaded_file($photo['tmp_name'], $dstFile);
//
//自动缩放
$imgInfo = @getimagesize($dstFile);
$maxPicWidth = intval(loadConfig('cmsContent', 'maxPicWidth'));
$maxPicWidth = $maxPicWidth < 1 ? 500 : $maxPicWidth;
if ($imgInfo[0] > $maxPicWidth) {
$newWidth = $maxPicWidth;
$newHeight = $imgInfo[1] * $newWidth / $imgInfo[0];
} else {
$newWidth = $imgInfo[0];
$newHeight = $imgInfo[1];
}
bpBase::loadSysClass('image');
bpBase::loadSysClass('watermark');
image::zfResize($dstFile, $dstFolder . $time . $rand . '.jpg', $newWidth, $newHeight, 1, 2, 0, 0, 1);
//delete the temporary file
@unlink($dstFile);
$location = CMS_DIR_PATH . $pathInfo['url'] . $time . $rand . '.jpg';
//
bpBase::loadSysClass('image');
bpBase::loadSysClass('watermark');
$wm = new watermark();
$wm->wm($dstFolder . $time . $rand . '.jpg');
//
$filePath = $location;
//processing end
if ($error) {
$return = array('status' => '0', 'error' => $error);
} else {
$return = array('status' => '1', 'name' => ABS_PATH . $filePath);
// Our processing, we get a hash value from the file
$return['hash'] = '';
// ... and if available, we get image data
if ($imgInfo) {
$return['width'] = $newWidth;
$return['height'] = $newHeight;
$return['mime'] = $imgInfo['mime'];
$return['url'] = $filePath;
$return['randnum'] = rand(0, 999999);
}
}
// Output
if (isset($_REQUEST['response']) && $_REQUEST['response'] == 'xml') {
// header('Content-type: text/xml');
// Really dirty, use DOM and CDATA section!
echo '<response>';
foreach ($return as $key => $value) {
echo "<{$key}><![CDATA[{$value}]]></{$key}>";
}
echo '</response>';
} else {
// header('Content-type: application/json');
echo json_encode($return);
}
}
示例7: _upgrade_resaler
public function _upgrade_resaler()
{
$db = M('wechat_user');
$id = I('get.id');
$info = $db->find($id);
$this->assign('info', $info);
if ($arr = $this->_post()) {
$record = $db->where(array('username' => $arr['username']))->find();
if (!empty($record)) {
$this->error('账户名已经存在,请重新分配账户名');
} else {
$arr['password'] = md5($arr['password']);
$arr['role_id'] = 3;
//分销商
//生成邀请码
$invite_code = randStr();
$is_exist = $db->where(array('invite_code' => $invite_code))->find();
while (!empty($is_exist)) {
$invite_code = randStr();
}
$arr['invite_code'] = $invite_code;
$db->where(array('id' => $id))->save($arr);
$this->redirect('upgrade_resaler', array('id' => $id));
}
}
$this->display();
}
示例8: exit
<?php
if (!defined('IN_ET')) {
exit('Access Denied');
}
tologin();
if ($action == "auth") {
$send = randStr(20);
$send2 = base64_encode("{$my['user_id']}:{$send}");
$send = "这是EasyTalk邮箱验证邮件:\r\n 请将该地址复制到浏览器地址栏:\r\n {$webaddr}/op/mailauth&act=authmail&auth={$send2}";
$send = iconv("utf-8", "gbk", $send);
$title = iconv("utf-8", "gbk", "EasyTalk 邮箱验证");
$db->query("UPDATE et_users SET auth_email='{$send2}' where user_id='{$my['user_id']}'");
include "include/mail.class.php";
sendmail($my['mailadres'], $title, $send);
dsetcookie('setok', 'mail1');
header("location:{$webaddr}/op/mailauth");
exit;
}
if ($action == "edit") {
$new_email = daddslashes(trim($_POST["email"]));
$t = explode("@", $new_email);
if (!$t[1]) {
dsetcookie('setok', 'mail2');
header("location:{$webaddr}/op/mailauth");
exit;
} else {
if ($new_email && $new_email != $my[mailadres]) {
$query = $db->query("SELECT mailadres FROM et_users WHERE mailadres='{$new_email}'");
$row = $db->fetch_array($query);
if ($row) {
示例9: setAutologin
function setAutologin($id)
{
$hash = md5(randStr() . $id);
return $hash;
}
示例10: array
$res = array('flag' => 0);
if (strpos($_SERVER['HTTP_USER_AGENT'], "MicroMessenger")) {
require_once '../inc/common_hhr.php';
$is_reged = cloud_get_field('mobile', 'customers', " mobile = {$_POST['mobile']}");
if (empty($is_reged)) {
$openid = $_POST['openid'];
$realname = $_POST['realname'];
$sex = $_POST['sex'] == 0 ? 2 : $_POST['sex'];
//$province_txt= $_POST['province_txt'];
//$city_txt = $_POST['city_txt'];
$mobile = $_POST['mobile'];
$back_url = $_POST['back_url'];
$createtime = time();
$partner_id = cloud_get_field('partner_id', 'customers_from', "openid = '{$openid}'");
$number = 'M' . date('YmdHis') . randStr(6);
//echo
$field = "`number`,`partner_id`,`realname`,`sex`,`createtime`,`mobile`";
$value = "'{$number}','{$partner_id}','{$realname}','{$sex}','{$createtime}','{$mobile}'";
if (cloud_insert('customers', $field, $value)) {
$res = array('flag' => 1);
updateCustomerCount($partner_id);
}
}
//http://cloud.net:8083/plus/hhr_customers.php
}
die(json_encode($res));
function updateCustomerCount($partner_id)
{
$customer_count = cloud_get_field('customer_count', 'partners', "id = '{$partner_id}'");
if (empty($customer_count)) {
示例11: microtime
if ($res === true) {
echo 'loaded stim data <br>';
} else {
echo 'Err: failed to load stim data: ' . $dbConn->error . '<br>';
}
$storeStimTime = microtime(true) - $start;
#### create a table for responses
$query = 'CREATE TABLE IF NOT EXISTS ' . $respTable . ' (' . 'Username TEXT, ' . 'Response TEXT, ' . 'RT FLOAT, ' . 'Focus FLOAT, ' . 'RTfirst FLOAT, ' . 'RTlast FLOAT, ' . 'Accuracy FLOAT, ' . 'StrictAcc FLOAT, ' . 'LenientAcc FLOAT, ' . 'Timestamp TIMESTAMP' . ')';
$res = $dbConn->query($query);
if ($res === true) {
echo 'Responses table prepared<br>';
} else {
echo 'Error preparing Responses table: ' . $dbConn->error . '<br>';
}
#### generate a random response
$myResponses = array('Response' => 'blah blah' . randStr(), 'RT' => '13.283', 'RTfirst' => '6.231', 'RTlast' => '12.932', 'Focus' => '0.9834', 'NewResp' => 'haha yes! ' . randStr(), 'NewResp2' => 'another!' . randStr());
#### add info to responses
$myResponses['Username'] = 'participant001';
$myResponses['Timestamp'] = time();
$respTime = microtime(true);
#### check for new columns
$respCols = array();
$res = $dbConn->query('SHOW COLUMNS FROM ' . $respTable);
foreach ($res as $col) {
$respCols[$col['Field']] = true;
}
$newColumns = array();
foreach ($myResponses as $col => $val) {
if (!isset($respCols[$col])) {
$newColumns[] = 'ADD ' . $col . ' TEXT';
}
示例12: autoSaveRemoteImage
public function autoSaveRemoteImage($str, $baseURI = '')
{
$str = stripslashes($str);
$watermark = bpBase::loadSysCLass('watermark');
$img_array = array();
//$str = stripslashes($str);
if (get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
preg_match_all('#src="(http://(((?!").)+).(jpg|gif|bmp|png))"#i', $str, $img_array);
$img_array_urls = array_unique($img_array[1]);
$dstFolder = ABS_PATH . 'upload' . DIRECTORY_SEPARATOR . 'images';
@chmod($dstFolder, 0777);
if ($baseURI) {
$img_array_urls = $this->_expandlinks($img_array_urls, $baseURI);
if ($img_array_urls) {
exit;
}
}
if ($img_array_urls) {
$i = 0;
$time = SYS_TIME;
foreach ($img_array_urls as $k => $v) {
if (!strpos($v, $_SERVER['HTTP_HOST'])) {
//不保存本站的
$filenames = explode('.', $v);
$filenamesCount = count($filenames);
//
$year = date('Y', $time);
$month = date('m', $time);
$pathInfo = upFileFolders($time);
$dstFolder = $pathInfo['path'];
$rand = randStr(4);
$filePath = $dstFolder . $time . $rand . '.' . $filenames[$filenamesCount - 1];
//
@httpCopy($v, $filePath, 5);
//自动缩放
$imgInfo = @getimagesize($filePath);
$maxPicWidth = intval(loadConfig('cmsContent', 'maxPicWidth'));
$maxPicWidth = $maxPicWidth < 1 ? 500 : $maxPicWidth;
if ($imgInfo[0] > $maxPicWidth) {
$newWidth = $maxPicWidth;
$newHeight = $imgInfo[1] * $newWidth / $imgInfo[0];
bpBase::loadSysClass('image');
image::zfResize($filePath, $filePath, $newWidth, $newHeight, 1, 2, 0, 0, 1);
}
//
if (file_exists($filePath)) {
$watermark->wm($filePath);
$str = str_replace($v, 'http://' . $_SERVER['HTTP_HOST'] . CMS_DIR_PATH . $pathInfo['url'] . $time . $rand . '.' . $filenames[$filenamesCount - 1], $str);
}
}
$i++;
}
}
return $str;
}
示例13: mysql_query
$met_skin_table = "{$tablepre}skin_table";
$query = " INSERT INTO {$met_admin_table} set\n admin_id = '{$regname}',\n admin_pass = '{$regpwd}',\n\t\t\t\t\t admin_introduction = '创始人',\n\t\t\t\t\t admin_group = '10000',\n\t\t\t\t admin_type = 'metinfo',\n\t\t\t\t\t admin_email = '{$email}',\n\t\t\t\t\t admin_mobile = '{$tel}',\n\t\t\t\t\t admin_register_date= '{$m_now_date}',\n\t\t\t\t\t admin_shortcut='[{\"name\":\"lang_skinbaseset\",\"url\":\"system/basic.php?anyid=9&lang=cn\",\"bigclass\":\"1\",\"field\":\"s1001\",\"type\":\"2\",\"list_order\":\"10\",\"protect\":\"1\",\"hidden\":\"0\",\"lang\":\"lang_skinbaseset\"},{\"name\":\"lang_indexcolumn\",\"url\":\"column/index.php?anyid=25&lang=cn\",\"bigclass\":\"1\",\"field\":\"s1201\",\"type\":\"2\",\"list_order\":\"0\",\"protect\":\"1\",\"hidden\":\"0\",\"lang\":\"lang_indexcolumn\"},{\"name\":\"lang_unitytxt_75\",\"url\":\"interface/skin_editor.php?anyid=18&lang=cn\",\"bigclass\":\"1\",\"field\":\"s1101\",\"type\":\"2\",\"list_order\":\"0\",\"protect\":\"1\",\"hidden\":\"0\",\"lang\":\"lang_unitytxt_75\"},{\"name\":\"lang_tmptips\",\"url\":\"interface/info.php?anyid=24&lang=cn\",\"bigclass\":\"1\",\"field\":\"\",\"type\":\"2\",\"list_order\":\"0\",\"protect\":\"1\",\"hidden\":\"0\",\"lang\":\"lang_tmptips\"},{\"name\":\"lang_mod2add\",\"url\":\"content/article/content.php?action=add&lang=cn&anyid=29\",\"bigclass\":\"1\",\"field\":\"\",\"type\":\"2\",\"list_order\":\"0\",\"protect\":\"0\",\"hidden\":\"0\",\"lang\":\"lang_mod2add\"},{\"name\":\"lang_mod3add\",\"url\":\"content/product/content.php?action=add&lang=cn&anyid=29\",\"bigclass\":\"1\",\"field\":\"\",\"type\":2,\"list_order\":\"0\",\"protect\":0}]',\n\t\t\t\t\t usertype \t = '3',\n\t\t\t\t\t content_type = '1',\n\t\t\t\t\t admin_ok = '1'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$query = " UPDATE {$met_config} set value='{$webname_cn}' where name='met_webname' and lang='cn'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$query = " UPDATE {$met_config} set value='{$webkeywords_cn}' where name='met_keywords' and lang='cn'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$query = " UPDATE {$met_config} set value='{$webname_en}' where name='met_webname' and lang='en'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$query = " UPDATE {$met_config} set value='{$webkeywords_en}' where name='met_keywords' and lang='en'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$query = " UPDATE {$met_config} set value='{$webname_tc}' where name='met_webname' and lang='tc'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$query = " UPDATE {$met_config} set value='{$webkeywords_tc}' where name='met_keywords' and lang='tc'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$force = randStr(7);
$query = " UPDATE {$met_config} set value='{$force}' where name='met_member_force'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$install_url = str_replace("install/index.php", "", $install_url);
$query = " UPDATE {$met_config} set value='{$install_url}' where name='met_weburl'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$query = " UPDATE {$met_lang} set met_weburl='{$install_url}' where lang!='metinfo'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
$adminurl = $install_url . 'admin/';
$query = " UPDATE {$met_column} set out_url='{$adminurl}' where module='0'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
if ($tcdata == "yes") {
$query = "UPDATE {$met_config} set value='0' where name='met_ch_lang' and lang='metinfo'";
mysql_query($query) or die('写入数据库失败: ' . mysql_error());
}
$SQL = "SELECT * FROM {$met_skin_table}";
示例14: getHash
function getHash()
{
return $_SESSION['hash_code'] = randStr();
}
示例15: randStr
if ($tag0 == 1) {
echo 'ok';
} else {
function randStr($len)
{
$chars = 'ABDEFGHJKLMNPQRSTVWXYabdefghijkmnpqrstvwxy23456789';
// characters to build the password from
mt_srand((double) microtime() * 1000000 * getmypid());
// seed the random number generater (must be done)
$password = '';
while (strlen($password) < $len) {
$password .= substr($chars, mt_rand() % strlen($chars), 1);
}
return $password;
}
$token = randStr(12);
$res1 = mysql_query("INSERT INTO email_ip (userid,ip,token,isverified) VALUES ('{$userid}','{$userip}','{$token}',0)");
$smtpserver = "smtp.163.com";
$smtpserverport = 25;
$smtpusermail = "nstest@163.com";
$smtpuser = "nstest";
$smtppass = "code";
$smtp = new Smtp($smtpserver, $smtpserverport, true, $smtpuser, $smtppass);
$emailtype = "HTML";
$smtpemailto = $email;
$smtpemailfrom = $smtpusermail;
$emailsubject = "异地登陆验证";
$emailbody = "IP地址:" . $userip . "用您的账号进行登录,若是您本人操作,请访问(http://localhost/cucyue/check.php?token=" . $token . ") 进行认证。若非您本人操作,则您的密码很可能已经泄露,请尽快修改密码!";
$rs = $smtp->sendmail($smtpemailto, $smtpemailfrom, $emailsubject, $emailbody, $emailtype);
echo '异地登陆,请登录邮箱核验您的IP地址';
}