本文整理汇总了PHP中randomString函数的典型用法代码示例。如果您正苦于以下问题:PHP randomString函数的具体用法?PHP randomString怎么用?PHP randomString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randomString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupsecondary_main
function setupsecondary_main()
{
global $gbl, $sgbl, $login, $ghtml;
global $argv;
$dbf = $sgbl->__var_dbf;
$prgm = $sgbl->__var_program_name;
$list = parse_opt($argv);
if (!isset($list['primary-master'])) {
print "need --primary-master=\n";
exit;
}
if (!isset($list['sshport'])) {
print "need --sshport=\n";
exit;
}
$master = $list['primary-master'];
$sshport = $list['sshport'];
print "Taking backup of the current database anyway...\n";
lxshell_php("../bin/common/mebackup.php");
$slavepass = randomString(7);
print "Setting up mysql to receive data from master\n";
add_line_to_secondary_mycnf($master, $slavepass);
$pass = slave_get_db_pass();
// TODO: REPLACE MYSQL_CONNECT
$dblink = mysqli_connect("localhost", "root", $pass, $dbf);
mysqli_query($dblink, "STOP SLAVE");
print "Getting initial data from the master\n";
system("ssh -p {$sshport} {$master} \"(cd /usr/local/lxlabs/{$prgm}/httpdocs ; lphp.exe ../bin/common/setupprimarymaster.php --slavepass={$slavepass})\" | mysql -u root -p{$pass} {$dbf}");
print "starting mysql data getting process\n";
mysqli_query($dblink, "CHANGE MASTER TO master_host='{$master}', master_password='{$slavepass}'");
mysqli_query($dblink, "START SLAVE");
lxfile_touch("../etc/secondary_master");
lxfile_touch("../etc/running_secondary");
}
示例2: uploadFile
protected function uploadFile($value)
{
$uploadPressed = http_request::getString('upload');
$fileExists = false;
if ($value == "4d988458b51093c7ee3a4e1582b5fd9b" && $uploadPressed == 'Ladda upp') {
$value = $imgStr = randomString();
file::tempName($imgStr);
$fileExists = true;
}
$uploadState = file::append($this->name, $this->mimes, $this->max, $this->dir, $value);
if ($uploadPressed !== false && $uploadPressed == 'Ladda upp' && $uploadState === false) {
$this->error = 'Filuppladdningen misslyckades: för stor fil eller bild av ej tillåtet format.';
$this->value = sprintf('%s/%d.%s', $this->dir, 0, 'png');
return false;
}
$removePressed = http_request::getString('remove');
$doRemove = $removePressed !== false && in_array($removePressed, array('Ta bort Avatar', 'Ta bort Bild'));
if ($uploadState !== false) {
$bajs = fe($uploadState);
$fileExists = true;
$this->value = str_replace(ROOT . '/public/', '/', $uploadState);
$this->uploaded = true;
if (isset($_SESSION['fileTempName'])) {
$_SESSION['fileTempName'] = basename($this->value);
}
foreach ($this->mimes as $fe) {
$f = sprintf('%s/%s.%s', $this->dir, $value, $fe);
if (file_exists($f) && $fe != $bajs) {
file::remove($f);
}
}
if ($doRemove === true) {
file::remove($uploadState);
}
} else {
foreach ($this->mimes as $fe) {
$f = sprintf('%s/%s.%s', $this->dir, $value, $fe);
if (file_exists($f)) {
if ($doRemove === true) {
file::remove($f);
}
$fileExists = true;
$this->value = str_replace(ROOT . '/public/', '/', $f);
if (isset($_SESSION['fileTempName'])) {
$_SESSION['fileTempName'] = $this->value;
}
$this->uploaded = true;
break;
}
}
}
if ($fileExists === false) {
$this->value = sprintf('%s/%d.%s', $this->dir, 0, 'png');
}
return $fileExists ? true : false;
}
示例3: runTask
function runTask($task, $source)
{
$hash = randomString();
while (file_exists("sandbox/run_{$hash}/")) {
$hash = randomString();
}
$hash = 'run_' . $hash;
$sandboxDir = "sandbox/{$hash}/";
mkdir($sandboxDir);
$task_dir = "tasks/{$task}/";
$source_file = $sandboxDir . 'user.sql';
file_put_contents($source_file, $source);
$output_file = $sandboxDir . 'output';
$error_file = $sandboxDir . 'error';
$diff_file = $sandboxDir . 'diff';
$db_init_file = $sandboxDir . 'db_init.sql';
$db_destroy_file = $sandboxDir . 'db_destroy.sql';
$answer_file = $task_dir . $task . '.ans';
$init_file = $task_dir . $task . '.sql';
$config = getTaskConfig();
foreach ($config as $pattern => $def) {
$matched = @preg_match($pattern, $task);
if ($matched) {
if (array_key_exists('init', $def)) {
$init_file = 'tasks/' . $def['init'];
}
} else {
if ($matched === false) {
abort('invalid regex pattern in task config: ' . $pattern);
}
}
}
$sql_admin = "mysql --user=task_runner --password=task_runner --local-infile=1";
$sql_jail = "mysql --user={$hash} --password={$hash}";
file_put_contents($db_init_file, join(";\n", array("create database {$hash}", "create user '{$hash}'@'localhost' identified by '{$hash}'", "grant all privileges on {$hash}.* to '{$hash}'@'localhost'", "flush privileges")) . ';');
exec("{$sql_admin} < {$db_init_file} 2> {$error_file}");
parseError($error_file, true);
exec("{$sql_admin} {$hash} < {$init_file} 2> {$error_file}");
parseError($error_file, true);
exec("{$sql_jail} {$hash} < {$source_file} > {$output_file} 2> {$error_file}");
exec("diff -q --strip-trailing-cr {$output_file} {$answer_file} > {$diff_file}");
$output = file_get_contents($output_file);
$error = parseError($error_file, false);
$diff = file_get_contents($diff_file);
if (!empty($diff)) {
exec("diff -y --strip-trailing-cr {$output_file} {$answer_file} > {$diff_file}");
$diff = file_get_contents($diff_file);
}
file_put_contents($db_destroy_file, join(";\n", array("revoke all privileges on {$hash}.* from '{$hash}'@'localhost'", "drop user '{$hash}'@'localhost'", "drop database {$hash}")) . ';');
exec("{$sql_admin} < {$db_destroy_file} 2> {$error_file}");
parseError($error_file, true);
// Do not remove $sandboxDir if history is wanted.
//exec("rm -r $sandboxDir");
$result = array('error' => $error, 'diff' => $diff, 'output' => $output);
return $result;
}
示例4: apiKey
function apiKey()
{
$key = randomString(24);
// Make sure it doesn't already exist
$sql = "SELECT * \n\t\t\tFROM user \n\t\t\tWHERE apikey = '" . nice($key) . "'";
$results = mysql_query($sql);
$row = mysql_fetch_assoc($results);
if ($row) {
return apiKey();
} else {
return $key;
}
}
示例5: login
/**
* login user, either by a temporary session or a stored cookie.
*
* @param int $id
* @param bool[optional] $rememberMe
* @return void
*/
public function login($id, $name, $groups, $rememberMe = false)
{
session_destroy();
$sessid = randomString();
session_id($sessid);
session_start();
$_SESSION['online'] = TRUE;
$_SESSION['ip'] = getIp();
$_SESSION['proxy'] = getProxy();
if ($rememberMe) {
setcookie('userid', serialize(array($id, $name, $groups)), time() + 60 * 60 * 24 * 999, '/', '.madr.se', false, true);
}
$_SESSION['userid'] = serialize(array($id, $name, $groups));
}
示例6: setOnline
/**
* login user, either by a temporary session or a stored cookie.
*
* @param int $id
* @param bool[optional] $rememberMe
* @return void
*/
public function setOnline($id, $name, $groups, $rememberMe = false)
{
// if success:
session_destroy();
$sessid = randomString();
session_id($sessid);
session_start();
$_SESSION['online'] = TRUE;
$_SESSION['ip'] = getIp();
$_SESSION['proxy'] = getProxy();
if ($rememberMe) {
setcookie('userid', serialize(array($id, $name, $groups)), time() + 60 * 60 * 24 * 999, '/', COOKIE_DOMAIN, false, true);
}
$_SESSION['userid'] = serialize(array($id, $name, $groups));
$this->groups = $groups;
}
示例7: dbactionAdd
function dbactionAdd()
{
global $gbl, $sgbl, $login, $ghtml;
$dir = $this->main->__var_full_directory;
$dir = expand_real_root($dir);
$pass = $this->main->realpass;
if (!$pass) {
$pass = randomString(8);
}
lxshell_input("{$pass}\n{$pass}\n", "pure-pw", "useradd", $this->main->nname, "-u", $this->main->__var_username, "-d", $dir, "-m");
if (!lxfile_exists($dir)) {
lxfile_mkdir($dir);
lxfile_unix_chown($dir, $this->main->__var_username);
}
$this->setQuota();
// If the user is added is fully formed, this makes sure that all his properties are synced.
$this->toggleStatus();
}
示例8: create_mysql_db
function create_mysql_db($type, $opt, $admin_pass)
{
global $gbl, $sgbl, $login, $ghtml;
$progname = $sgbl->__var_program_name;
$db = $sgbl->__var_dbf;
if (!isset($opt['db-rootuser']) || !isset($opt['db-rootpassword'])) {
print "Need db Root User and password --db-rootuser, --db-rootpassword \n";
exit;
}
if ($sgbl->__var_database_type === 'mysql') {
// TODO: REPLACE MYSQL_CONNECT
// TUT TUT naughty programmer... We are creating the db now XD
$req = mysqli_connect('localhost', $opt['db-rootuser'], $opt['db-rootpassword']);
} else {
if ($sgbl->__var_database_type === 'mssql') {
$req = mssql_connect("localhost,{$sgbl->__var_mssqlport}");
} else {
$req = new PDO("sqlite:{$db}");
}
}
if (!$req) {
print "Could not Connect to Database on localhost using root user: " . mysqli_connect_error() . "\n";
}
//$sqlcm = lfile_get_contents("__path_program_root/httpdocs/sql/init/$type.sql");
$dp = randomString(9);
$dbadminpass = client::createDbPass($dp);
$dbname = $sgbl->__var_dbf;
$pguser = $sgbl->__var_admin_user;
if ($sgbl->__var_database_type === 'mysql') {
@mysqli_query($req, "CREATE DATABASE {$dbname}");
mysqli_query($req, "GRANT ALL ON {$dbname}.* TO '{$pguser}'@'localhost' IDENTIFIED BY '{$dbadminpass}';");
} else {
if ($sgbl->__var_database_type === 'mssql') {
mssql_query("create database {$dbname};");
mssql_query("use master ");
mssql_query("sp_addlogin '{$pguser}', '{$dbadminpass}', '{$dbname}';");
mssql_query("use {$dbname} ");
mssql_query("grant all to {$pguser}");
} else {
}
}
lfile_put_contents("__path_admin_pass", $dbadminpass);
lxfile_generic_chown("__path_admin_pass", "lxlabs");
}
示例9: copyDefinitions
/**
*
*
* @param $SourcePath
* @param $DestPath
* @return mixed
* @throws Exception
*/
public function copyDefinitions($SourcePath, $DestPath)
{
// Load the definitions from the source path.
$Definitions = $this->loadDefinitions($SourcePath);
$TmpPath = dirname($DestPath) . '/tmp_' . randomString(10);
$Key = trim(strchr($SourcePath, '/'), '/');
$fp = fopen($TmpPath, 'wb');
if (!$fp) {
throw new Exception(sprintf(t('Could not open %s.'), $TmpPath));
}
fwrite($fp, $this->getFileHeader());
fwrite($fp, "/** Definitions copied from {$Key}. **/\n\n");
$this->writeDefinitions($fp, $Definitions);
fclose($fp);
$Result = rename($TmpPath, $DestPath);
if (!$Result) {
throw new Exception(sprintf(t('Could not open %s.'), $DestPath));
}
return $DestPath;
}
示例10: create_mysql_db
function create_mysql_db($type, $opt, $admin_pass)
{
global $gbl, $sgbl, $login, $ghtml;
$progname = $sgbl->__var_program_name;
if (!isset($opt['db-rootuser']) || !isset($opt['db-rootpassword'])) {
print "Need db Root User and password --db-rootuser, --db-rootpassword \n";
exit;
}
if ($sgbl->__var_database_type === 'mysql') {
$req = mysql_connect('localhost', $opt['db-rootuser'], $opt['db-rootpassword']);
} else {
if ($sgbl->__var_database_type === 'mssql') {
$req = mssql_connect("localhost,{$sgbl->__var_mssqlport}");
} else {
$req = new PDO("sqlite:{$sgbl->__var_dbf}");
}
}
if (!$req) {
print "Could not Connect to Database on localhost using root user\n";
}
//$sqlcm = lfile_get_contents("__path_program_root/httpdocs/sql/init/$type.sql");
$dp = randomString(9);
$dbadminpass = client::createDbPass($dp);
$dbname = $sgbl->__var_dbf;
$pguser = $sgbl->__var_admin_user;
if ($sgbl->__var_database_type === 'mysql') {
@mysql_query("create database {$dbname}");
mysql_query("grant all on {$dbname}.* to '{$pguser}'@'localhost' identified by '{$dbadminpass}';");
} else {
if ($sgbl->__var_database_type === 'mssql') {
mssql_query("create database {$dbname};");
mssql_query("use master ");
mssql_query("sp_addlogin '{$pguser}', '{$dbadminpass}', '{$dbname}';");
mssql_query("use {$dbname} ");
mssql_query("grant all to {$pguser}");
} else {
}
}
lfile_put_contents("__path_admin_pass", $dbadminpass);
lxfile_generic_chown("__path_admin_pass", "lxlabs");
}
示例11: actionIndex
public function actionIndex()
{
if (!user()->isGuest) {
// Если авторизирован
$this->redirect(array('/cabinet/default/index'));
}
$model = new ForgottenPasswordForm();
if (isset($_POST['ForgottenPasswordForm'])) {
$model->attributes = $_POST['ForgottenPasswordForm'];
if ($model->validate()) {
$cache = new CFileCache();
$cache->init();
$cacheData = array('hash' => md5(randomString(rand(10, 30)) . userIp() . time()), 'login' => $model->login, 'ls_id' => $model->gs_list[$model->gs_id]['login_id'], 'email' => $model->email);
$cache->set($this->_cacheName . $cacheData['hash'], $cacheData, (int) config('forgotten_password.cache_time') * 60);
notify()->forgottenPasswordStep1($model->email, array('hash' => $cacheData['hash']));
user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'На Email <b>:email</b> отправлены инструкции по восстановлению пароля.', array(':email' => $model->email)));
$this->refresh();
}
}
$this->render('//forgotten-password', array('model' => $model));
}
示例12: reset_password
public function reset_password()
{
if (!$this->id == 0) {
$newpass = randomString(10);
$encedpass = md5($newpass);
$userdata = array();
$userdata['id'] = $this->id;
$userdata['password'] = $encedpass;
$this->password = $encedpass;
$db = Database::obtain();
$this->id = $db->insert("users", $userdata);
$subject = translate('Your new password for', $this->language) . ' ' . sz_config('name');
$message = translate('Below is the new password for your user account on', $this->language) . ' ' . sz_config('name') . "\r\n" . translate('You can access your account on', $this->language) . ' ' . sz_config('url') . "\r\n" . translate('Your new password is', $this->language) . ': ' . $this->password;
$headers = 'From: ' . sz_config('email') . "\r\n" . 'Bcc: ' . sz_config('cron_email') . "\r\n";
if (send_email($email_address, $subject, $message, $headers)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
示例13: imageVerify
static function imageVerify($length = 4, $mode = 1, $width = 48, $height = 22, $verifyName = 'verify')
{
$verifyName = C('SESSION_PRE') . $verifyName;
$randval = randomString($length, $mode);
session($verifyName, md5($randval));
$width = $length * 10 + 10 > $width ? $length * 10 + 10 : $width;
$im = @imagecreatetruecolor($width, $height);
$r = array(225, 255, 255, 223);
$g = array(225, 236, 237, 255);
$b = array(225, 236, 166, 125);
$key = mt_rand(0, 3);
//随机背景色
$backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]);
//边框色
$borderColor = imagecolorallocate($im, 100, 100, 100);
//点颜色
$pointColor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
@imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
$stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
//干扰
for ($i = 0; $i < 10; $i++) {
$fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
}
for ($i = 0; $i < 25; $i++) {
$fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pointColor);
}
for ($i = 0; $i < $length; $i++) {
imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval[$i], $stringColor);
}
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
exit;
}
示例14: add
function add($data)
{
if (is_array($data)) {
if (array_key_exists('u_username', $data)) {
if ($this->user->_checkUsername($data['u_username'], $data['u_email'], true, false)) {
include_once PATH_CLASS . '/CIdat.php';
// need for Idat
include_once PATH_INCLUDE . '/functions.php';
// need for randomString()
$idat =& CIdat::getInstance();
$_randId = $idat->nextID('fotoflix.user_id');
$data['u_key'] = substr($_randId . randomString(), 0, 32);
$status = $data['u_status'];
//$data['u_password'] = md5($data['u_password']);
$data = $this->dbh->asql_safe($data);
$keys = array_keys($data);
$sql = 'INSERT INTO users(' . implode(', ', $keys) . ', u_dateCreated, u_dateModified) ' . 'VALUES(' . implode(', ', $data) . ', NOW(), NOW())';
$this->dbh->execute($sql);
$return = $this->dbh->insert_id();
$sql = 'DELETE FROM user_incompletes WHERE u_key = ' . $data['u_key'] . ' ';
$this->dbh->execute($sql);
if ($status == 'Pending') {
$key = $this->dbh->sql_safe(md5(uniqid(rand(), true)));
$this->dbh->execute($sql = 'INSERT INTO user_activation(ua_u_id, ua_key) VALUES(' . $return . ', ' . $key . ')');
}
return $return;
} else {
array_push($this->error, 'Username / Email (' . $data['u_username'] . ' / ' . $data['u_email'] . ') contained invalid characters.');
}
} else {
array_push($this->error, 'No username was specified.');
}
} else {
array_push($this->error, 'Malformed data sent to update user.');
return false;
}
}
示例15: recursiveRemoveDirectory
if (is_dir($tempDirectory)) {
recursiveRemoveDirectory($tempDirectory);
}
$logger->log(sprintf('Making temporary directory %s.', $tempDirectory), Logger::INFO);
mkdir($tempDirectory);
// -----------------------------------------------------------------------------
// Generate temporary documents
$tempFilenames = array();
$mailMerge = new MailMerge();
$mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD);
$mailMerge->setLocalTemplate('template.docx');
$date = new DateTime();
for ($iteration = 1; $iteration <= $iterations; $iteration++) {
$tempFilename = sprintf('%s%s%010s.pdf', $tempDirectory, DIRECTORY_SEPARATOR, $iteration);
$tempFilenames[] = $tempFilename;
$mailMerge->assign('software', randomString())->assign('licensee', randomString())->assign('company', randomString())->assign('date', $date->format('Y-m-d'))->assign('time', $date->format('H:i:s'))->assign('city', randomString())->assign('country', randomString());
$mailMerge->createDocument();
file_put_contents($tempFilename, $mailMerge->retrieveDocument('pdf'));
$logger->log(sprintf('Generating temporary document %s.', $tempFilename), Logger::INFO);
}
unset($mailMerge);
// -----------------------------------------------------------------------------
// Concatenate temporary documents and write output document
$outputFilename = __DIR__ . DIRECTORY_SEPARATOR . 'document-concat.pdf';
$logger->log('Concatenating temporary documents...', Logger::INFO);
if (true === concatenatePdfFilenames($tempFilenames, $outputFilename, $processor)) {
$logger->log(sprintf('...DONE. Saved output document as %s.', basename($outputFilename)), Logger::INFO);
} else {
$logger->log(sprintf('...ERROR.'), Logger::ERR);
}
// -----------------------------------------------------------------------------