本文整理汇总了PHP中zen_rand函数的典型用法代码示例。如果您正苦于以下问题:PHP zen_rand函数的具体用法?PHP zen_rand怎么用?PHP zen_rand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zen_rand函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: zen_create_random_value
function zen_create_random_value($length, $type = 'mixed')
{
if ($type != 'mixed' && $type != 'chars' && $type != 'digits') {
return false;
}
$rand_value = '';
while (strlen($rand_value) < $length) {
if ($type == 'digits') {
$char = zen_rand(0, 9);
} else {
$char = chr(zen_rand(0, 255));
}
if ($type == 'mixed') {
if (eregi('^[a-z0-9]$', $char)) {
$rand_value .= $char;
}
} elseif ($type == 'chars') {
if (eregi('^[a-z]$', $char)) {
$rand_value .= $char;
}
} elseif ($type == 'digits') {
if (ereg('^[0-9]$', $char)) {
$rand_value .= $char;
}
}
}
return $rand_value;
}
示例2: zen_create_random_value
function zen_create_random_value($length, $type = 'mixed')
{
if ($type != 'mixed' && $type != 'chars' && $type != 'digits') {
return false;
}
$rand_value = '';
while (strlen($rand_value) < $length) {
if ($type == 'digits') {
$char = zen_rand(0, 9);
} else {
$char = chr(zen_rand(0, 255));
}
if ($type == 'mixed') {
if (preg_match('/^[a-z0-9]$/i', $char)) {
$rand_value .= $char;
}
} elseif ($type == 'chars') {
if (preg_match('/^[a-z]$/i', $char)) {
$rand_value .= $char;
}
} elseif ($type == 'digits') {
if (preg_match('/^[0-9]$/', $char)) {
$rand_value .= $char;
}
}
}
if ($type == 'mixed' && !preg_match('/^(?=.*[\\w]+.*)(?=.*[\\d]+.*)[\\d\\w]{' . $length . ',}$/', $rand_value)) {
$rand_value .= zen_rand(0, 9);
}
return $rand_value;
}
示例3: zen_encrypt_password
function zen_encrypt_password($plain)
{
$password = '';
for ($i = 0; $i < 10; $i++) {
$password .= zen_rand();
}
$salt = substr(md5($password), 0, 2);
$password = md5($salt . $plain) . ':' . $salt;
return $password;
}
示例4: zen_random_name
function zen_random_name()
{
$letters = 'abcdefghijklmnopqrstuvwxyz';
$dirname = '.';
$length = floor(zen_rand(16, 20));
for ($i = 1; $i <= $length; $i++) {
$q = floor(zen_rand(1, 26));
$dirname .= $letters[$q];
}
return $dirname;
}
示例5: zen_random_charcode
function zen_random_charcode($length)
{
$arraysize = 34;
$chars = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$code = '';
for ($i = 1; $i <= $length; $i++) {
$j = floor(zen_rand(0, $arraysize));
$code .= $chars[$j];
}
return $code;
}
示例6: zen_random_name
function zen_random_name()
{
$letters = 'abcdefghijklmnopqrstuvwxyz';
$dirname = '.';
if (defined('DOWNLOADS_SKIP_DOT_PREFIX_ON_REDIRECT') && DOWNLOADS_SKIP_DOT_PREFIX_ON_REDIRECT === TRUE) {
$dirname = '';
}
$length = floor(zen_rand(16, 20));
for ($i = 1; $i <= $length; $i++) {
$q = floor(zen_rand(1, 26));
$dirname .= $letters[$q];
}
return $dirname;
}
示例7: ExecuteRandom
function ExecuteRandom($zf_sql, $zf_limit = 0, $zf_cache = false, $zf_cachetime = 0)
{
// if ($zf_limit) {
// $zf_sql = $zf_sql . ' LIMIT ' . $zf_limit;
// }
//echo $zf_sql . '<br />';
$time_start = explode(' ', microtime());
$obj = new queryFactoryResult();
$obj->result = array();
if (!$this->db_connected) {
$this->set_error('0', DB_ERROR_NOT_CONNECTED);
}
$zp_db_resource = @pg_query($this->link, $zf_sql);
if (!$zp_db_resource) {
$this->set_error(pg_last_error());
}
$obj->resource = $zp_db_resource;
$obj->cursor = 0;
$obj->Limit = $zf_limit;
if ($obj->RecordCount() > 0) {
$obj->EOF = false;
$zp_Start_row = 0;
if ($zf_limit) {
$zp_start_row = zen_rand(0, $obj->RecordCount() - $zf_limit);
}
$obj->Move($zp_start_row);
$obj->Limit = $zf_limit;
$zp_ii = 0;
while (!$obj->EOF) {
$zp_result_array = @pg_fetch_array($zp_db_resource, NULL, PGSQL_ASSOC);
if ($zp_ii == $zf_limit) {
$obj->EOF = true;
}
if ($zp_result_array) {
while (list($key, $value) = each($zp_result_array)) {
if (!ereg('^[0-9]', $key)) {
// echo $key . '=' . $value . '<br />';
$obj->result[$zp_ii][$key] = $value;
}
}
} else {
$obj->Limit = $zp_ii;
$obj->EOF = true;
}
$zp_ii++;
}
$obj->result_random = array_rand($obj->result, sizeof($obj->result));
// echo sizeof($obj->result) . " result array ";
// print_r($obj->result);
// echo '<br /><br />';
// echo 'random array ';
// print_r($obj);
if (is_array($obj->result_random)) {
$zp_ptr = $obj->result_random[$obj->cursor];
} else {
$zp_ptr = $obj->result_random;
}
while (list($key, $value) = each($obj->result[$zp_ptr])) {
if (!ereg('^[0-9]', $key)) {
$obj->fields[$key] = $value;
}
}
$obj->EOF = false;
} else {
$obj->EOF = true;
}
$time_end = explode(' ', microtime());
$query_time = $time_end[1] + $time_end[0] - $time_start[1] - $time_start[0];
$this->total_query_time += $query_time;
$this->count_queries++;
return $obj;
}
示例8: zen_random_select
function zen_random_select($query)
{
global $db;
$random_product = '';
$random_query = $db->Execute($query);
$num_rows = $random_query->RecordCount();
if ($num_rows > 1) {
$random_row = zen_rand(0, $num_rows - 1);
$random_query->Move($random_row);
}
return $random_query;
}
示例9: ExecuteRandomMulti
function ExecuteRandomMulti($zf_sql, $zf_limit = 0, $zf_cache = false, $zf_cachetime = 0)
{
$this->zf_sql = $zf_sql;
$time_start = explode(' ', microtime());
$obj = new queryFactoryResult();
$obj->result = array();
if (!$this->db_connected) {
if (!$this->connect($this->host, $this->user, $this->password, $this->database, $this->pConnect, $this->real)) {
$this->set_error('0', DB_ERROR_NOT_CONNECTED);
}
}
$zp_db_resource = @mysql_query($zf_sql, $this->link);
if (!$zp_db_resource) {
$this->set_error(mysql_errno(), mysql_error());
}
if (!is_resource($zp_db_resource)) {
$obj = null;
return true;
}
$obj->resource = $zp_db_resource;
$obj->cursor = 0;
$obj->Limit = $zf_limit;
if ($obj->RecordCount() > 0 && $zf_limit > 0) {
$obj->EOF = false;
$zp_Start_row = 0;
if ($zf_limit) {
$zp_start_row = zen_rand(0, $obj->RecordCount() - $zf_limit);
}
$obj->Move($zp_start_row);
$obj->Limit = $zf_limit;
$zp_ii = 0;
while (!$obj->EOF) {
$zp_result_array = @mysql_fetch_array($zp_db_resource);
if ($zp_ii == $zf_limit) {
$obj->EOF = true;
}
if ($zp_result_array) {
while (list($key, $value) = each($zp_result_array)) {
$obj->result[$zp_ii][$key] = $value;
}
} else {
$obj->Limit = $zp_ii;
$obj->EOF = true;
}
$zp_ii++;
}
$obj->result_random = array_rand($obj->result, sizeof($obj->result));
if (is_array($obj->result_random)) {
$zp_ptr = $obj->result_random[$obj->cursor];
} else {
$zp_ptr = $obj->result_random;
}
while (list($key, $value) = each($obj->result[$zp_ptr])) {
if (!preg_match('/^[0-9]/', $key)) {
$obj->fields[$key] = $value;
}
}
$obj->EOF = false;
} else {
$obj->EOF = true;
}
$time_end = explode(' ', microtime());
$query_time = $time_end[1] + $time_end[0] - $time_start[1] - $time_start[0];
$this->total_query_time += $query_time;
$this->count_queries++;
return $obj;
}
示例10: session_start
function session_start()
{
global $session, $SID, $_COOKIE, $_GET, $_POST;
// Define the global variable $SID?
$define_sid = true;
// Send the session cookie?
$send_cookie = true;
// Is track_vars enabled?
$track_vars = isset($_COOKIE) || isset($_GET) || isset($_POST) ? true : false;
// Check if session_start() has been called once already
if ($session->nr_open_sessions != 0) {
return false;
}
// If our only resource is the global symbol_table, then check it.
// If track_vars are enabled, we prefer these, because they are more
// reliable, and we always know whether the user has accepted the
// cookie.
if (isset($GLOBALS[$session->name]) && !empty($GLOBALS[$session->name]) && !$track_vars) {
$session->id = $GLOBALS[$session->name];
$send_cookie = false;
}
// Now check the track_vars. Cookies are preferred, because initially
// cookie and get variables will be available.
if (empty($session->id) && $track_vars) {
if (isset($_COOKIE[$session->name])) {
$session->id = $_COOKIE[$session->name];
$define_sid = false;
$send_cookie = false;
}
if (isset($_GET[$session->name])) {
$session->id = $_GET[$session->name];
}
if (isset($_POST[$session->name])) {
$session->id = $_POST[$session->name];
}
}
/*
// Check the REQUEST_URI symbol for a string of the form
// '<session-name>=<session-id>' to allow URLs of the form
// http://yoursite/<session-name>=<session-id>/script.php
if (empty($session->id)) {
eregi($session->name . '=([^/]+)', $GLOBALS['REQUEST_URI'], $regs);
$regs[1] = trim($regs[1]);
if (!empty($regs[1])) {
$session->id = $regs[1];
}
}
*/
// Check whether the current request was referred to by
// an external site which invalidates the previously found ID
if (!empty($session->id) && $session->referer_check) {
$url = parse_url($GLOBALS['HTTP_REFERER']);
if (trim($url['host']) != $GLOBALS['SERVER_NAME']) {
unset($session->id);
$send_cookie = true;
$define_sid = true;
}
}
// Do we have an existing session ID?
if (empty($session->id)) {
// Create new session ID
$session->id = _session_create_id();
}
// Is use_cookies set to false?
if (!$session->use_cookies && $send_cookie) {
$define_sid = true;
$send_cookie = false;
}
// Should we send a cookie?
if ($send_cookie) {
setcookie($session->name, $session->id, $session->cookie_lifetime, $session->cookie_path, $session->cookie_domain);
}
// Should we define the SID?
if ($define_sid) {
$SID = $session->name . '=' . $session->id;
}
$session->nr_open_sessions++;
// Send caching headers
// Start session
$mod = $GLOBALS[$session->mod_name];
if (!$mod->open($session->save_path, $session->name)) {
die('Failed to initialize session module.');
}
// Read session data
if ($val = $mod->read($session->id)) {
// Decode session data
session_decode($val);
}
// Send HTTP cache headers
_session_cache_limiter();
// Check if we should clean up (call the garbage collection routines)
if ($session->gc_probability > 0) {
$randmax = getrandmax();
$nrand = (int) (100 * zen_rand() / $randmax);
if ($nrand < $session->gc_probability) {
$mod->gc($session->gc_maxlifetime);
}
}
if ($define_sid) {
define('SID', $SID);
//.........这里部分代码省略.........
示例11: encode
/**
* encode()
*
* Encodes and returns the email. Also stores
* it in the encoded member variable
*
* @return An associative array containing two elements,
* body and headers. The headers element is itself
* an indexed array.
* @access public
*/
function encode()
{
/* HPDL PHP3 */
// $encoded =& $this->_encoded;
$encoded = $this->_encoded;
if (zen_not_null($this->_subparts)) {
$boundary = '=_' . md5(uniqid(zen_rand()) . microtime());
$this->_headers['Content-Type'] .= ';' . $this->lf . chr(9) . 'boundary="' . $boundary . '"';
// Add body parts to $subparts
for ($i = 0; $i < count($this->_subparts); $i++) {
$headers = array();
/* HPDL PHP3 */
// $tmp = $this->_subparts[$i]->encode();
$_subparts = $this->_subparts[$i];
$tmp = $_subparts->encode();
reset($tmp['headers']);
while (list($key, $value) = each($tmp['headers'])) {
$headers[] = $key . ': ' . $value;
}
$subparts[] = implode($this->lf, $headers) . $this->lf . $this->lf . $tmp['body'];
}
$encoded['body'] = '--' . $boundary . $this->lf . implode('--' . $boundary . $this->lf, $subparts) . '--' . $boundary . '--' . $this->lf;
} else {
$encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding) . $this->lf;
}
// Add headers to $encoded
/* HPDL PHP3 */
// $encoded['headers'] =& $this->_headers;
$encoded['headers'] = $this->_headers;
return $encoded;
}