本文整理汇总了PHP中String::random方法的典型用法代码示例。如果您正苦于以下问题:PHP String::random方法的具体用法?PHP String::random怎么用?PHP String::random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类String
的用法示例。
在下文中一共展示了String::random方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFormTags
/**
* Returns the hidden captcha tags to put in your form
*
* @param string $formId [optional] The id to use to generate input elements (default = "hcptch")
* @param boolean $withImage [optional] The captcha use the classic image captcha
* @return string The tags to put in your form
*/
public static function getFormTags($formId = 'hcptch', $withImage = false)
{
// Get spinner vars
$now = time();
$name = String::random(array('numbers' => false, 'uppercase' => false));
// Generate the spinner
$spinner = array('timestamp' => $now, 'session_id' => session_id(), 'ip' => self::_getIp(), 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'hfield_name' => $name);
if ($withImage) {
$captcha = String::hrRandom(5);
$spinner['captcha'] = $captcha;
}
// Encrypt the spinner
$spinner = Security::encrypt(serialize($spinner));
// put a random invisible style, to fool spambots a little bit ;-)
$styles = array('position:absolute;left:-' . mt_rand(10000, 20000) . 'px;', 'display: none');
$style = $styles[array_rand($styles)];
// build tags
$tags = '<input type="hidden" name="' . $formId . '[spinner]" value="' . $spinner . '" />' . PHP_EOL;
$tags .= '<span style="' . $style . '"><input type="text" name="' . $formId . '[name]" value=""/></span>' . PHP_EOL;
if ($withImage) {
$tags .= self::_generateImage($captcha);
$tags .= '<input type="text" name="' . $formId . '[' . $name . ']" value="" autocomplete="off" />' . PHP_EOL;
} else {
$tags .= '<input type="hidden" name="' . $formId . '[' . $name . ']" value="' . $now . '" />' . PHP_EOL;
}
return $tags;
}
示例2: addFile
public function addFile(File $file, $filename = null)
{
// sanitize filename
if (!($filename = Sanitizer::filename($filename))) {
$filename = String::random(8);
}
$realFile = new File($filename);
// if file type is known, set new extension
$newFilename = $realFile->basename(false) . '.' . $realFile->extension();
// store files in flat hirarchy
$file = $file->move(new Dir(STATIC_DIR . $this->path), $newFilename, true);
$this->fromArray(array('filename' => $file->basename(), 'mime_type' => $file->mimeType()));
return $this;
}
示例3: recover
public function recover()
{
if (isset($_POST['email'])) {
$recover = new Users();
if ($recover->select(array('email' => $_POST['email']))) {
// Create a random password and update the table row
$recover->password = String::random();
$recover->update();
$msg = 'Your new password is: ' . $recover->password . '<br /><br />';
$msg .= 'Try logging in at <a href="' . WEB_ROOT . 'login/">' . WEB_ROOT . 'login/</a>';
Core_Helpers::send_html_mail($recover->email, 'Password Recovery', $msg, $data['config']->email_address);
Flash::set('<p class="flash success">Password has been reset and will be emailed to you shortly.</p>');
} else {
Flash::set('<p class="flash validation">Sorry, you have entered an email address that is not associated with any account.</p>');
}
}
$this->load_template('recover');
}
示例4: post_quenmk
public function post_quenmk()
{
$data = Input::all();
$valid = Validator::make($data, User::$quenmk_rules, User::$language);
if ($valid->passes()) {
$code = String::random(50);
$user = User::where('username', Input::get('username'))->get()->first();
if ($user == false) {
return Redirect::to(Session::get('url'))->withInput()->with('error_top', 'Tài khoản không tồn tại');
} else {
$mail = array('username' => $user->username, 'code' => $code, 'usermail' => $user->email);
$user->code = $code;
$user->save();
Mail::send('user.mail', $mail, function ($mess) use($mail) {
$mess->from('support@vieclamsinhviendanang.com', 'Việc làm sinh viên Đà Nẵng');
$mess->to($mail['usermail'], $mail['username']);
$mess->subject('Yêu cầu khôi phục mật khẩu');
});
return Redirect::to(Session::get('url'))->with('success_top', 'Vui lòng kiểm tra email và hoàn tất');
}
} else {
return Redirect::to(Session::get('url'))->withInput()->with('error_top', $valid->errors()->first());
}
}
示例5: isset
<?php
$root = '.';
include_once "{$root}/config.php";
include_once "{$root}/common.php";
$key = isset($_GET['k']) ? strtolower($_GET['k']) : 'default';
define('CAPTCHA_WIDTH', 150);
define('CAPTCHA_HEIGHT', 50);
/**
* Captcha case INsensitive.
*/
$captcha = strtolower(Session::captcha($key, String::random(CAPTCHA_LENGTH)));
$image = imagecreate(CAPTCHA_WIDTH, CAPTCHA_HEIGHT);
imagecolorallocate($image, 255, 255, 255);
$color = imagecolorallocate($image, mt_rand(0, 180), mt_rand(0, 180), mt_rand(0, 180));
$border = imagecolorallocate($image, 210, 210, 210);
$shadow = imagecolorallocate($image, 180, 180, 180);
for ($i = 0, $sup = CAPTCHA_WIDTH * CAPTCHA_HEIGHT / CAPTCHA_LENGTH; $i < $sup; $i++) {
imagesetpixel($image, mt_rand(0, CAPTCHA_WIDTH), mt_rand(0, CAPTCHA_HEIGHT), $color);
}
imagerectangle($image, 0, 0, CAPTCHA_WIDTH - 1, CAPTCHA_HEIGHT - 1, $border);
$angle = mt_rand(-3, 3);
imagettftext($image, 25, $angle, 12, 42, $shadow, "{$root}/themes/{$theme}/captcha.ttf", $captcha);
imagettftext($image, 25, $angle, 10, 40, $color, "{$root}/themes/{$theme}/captcha.ttf", $captcha);
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
示例6: testRandom
/**
* @covers Panadas\Util\String::random()
*/
public function testRandom()
{
$this->assertNotEquals(String::random(10), String::random(10));
$this->assertEquals(10, mb_strlen(String::random(10)));
}
示例7: testRandom
/**
* Tests the random string generator.
*/
public function testRandom()
{
for ($i = 1; $i <= 32; $i++) {
$random = String::random($i);
$this->assertEquals($i, strlen($random));
$this->assertRegExp('~^[a-z0-9]+$~i', $random);
}
}
示例8: _writeOtherCode
/**
* 扰乱字符
*
*/
protected function _writeOtherCode()
{
for ($i = 0; $i < 10; $i++) {
$color = imagecolorallocate($this->image, mt_rand(150, 225), mt_rand(150, 225), mt_rand(150, 225));
for ($j = 0; $j < 5; $j++) {
$char = String::random(1);
imagestring($this->image, 5, mt_rand(-10, $this->width), mt_rand(-10, $this->height), $char, $color);
}
}
}
示例9: testRandom
public function testRandom()
{
$string = new String("Test15");
$this->assertEquals(10, $string->length($string->random()));
$this->assertFalse($string->random() == $string->random());
}
示例10: _getKey
/**
* Return the unique key for the application or generate a new one and write it in webapp/config/.key
*
* @return string
*/
private static function _getKey()
{
$keyFile = WEBAPP_DIR . DS . 'config' . DS . '.key';
if (is_file($keyFile)) {
return file_get_contents($keyFile);
}
$rand = String::random(array('length' => 32, 'special' => true));
if (!file_put_contents($keyFile, $rand)) {
trigger_error('Cannot write the security key in ' . WEBAPP_DIR . DS . 'config', E_USER_ERROR);
}
return $rand;
}