本文整理汇总了PHP中uniqid函数的典型用法代码示例。如果您正苦于以下问题:PHP uniqid函数的具体用法?PHP uniqid怎么用?PHP uniqid使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uniqid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AddTextAdsExample
function AddTextAdsExample(AdWordsUser $user, $adGroupId)
{
// Get the service, which loads the required classes.
$adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
$numAds = 5;
$operations = array();
for ($i = 0; $i < $numAds; $i++) {
// Create text ad.
$textAd = new TextAd();
$textAd->headline = 'Cruise #' . uniqid();
$textAd->description1 = 'Visit the Red Planet in style.';
$textAd->description2 = 'Low-gravity fun for everyone!';
$textAd->displayUrl = 'www.example.com';
$textAd->finalUrls = array('http://www.example.com');
// Create ad group ad.
$adGroupAd = new AdGroupAd();
$adGroupAd->adGroupId = $adGroupId;
$adGroupAd->ad = $textAd;
// Set additional settings (optional).
$adGroupAd->status = 'PAUSED';
// Create operation.
$operation = new AdGroupAdOperation();
$operation->operand = $adGroupAd;
$operation->operator = 'ADD';
$operations[] = $operation;
}
// Make the mutate request.
$result = $adGroupAdService->mutate($operations);
// Display results.
foreach ($result->value as $adGroupAd) {
printf("Text ad with headline '%s' and ID '%s' was added.\n", $adGroupAd->ad->headline, $adGroupAd->ad->id);
}
}
示例2: addnew
function addnew()
{
if ($_POST) {
$image = $_FILES['logo'];
$image_name = $image['name'];
$image_tmp = $image['tmp_name'];
$image_size = $image['size'];
$error = $image['error'];
$file_ext = explode('.', $image_name);
$file_ext = strtolower(end($file_ext));
$allowed_ext = array('jpg', 'jpeg', 'bmp', 'png', 'gif');
$file_on_server = '';
if (in_array($file_ext, $allowed_ext)) {
if ($error === 0) {
if ($image_size < 3145728) {
$file_on_server = uniqid() . '.' . $file_ext;
$destination = './brand_img/' . $file_on_server;
move_uploaded_file($image_tmp, $destination);
}
}
}
$values = array('name' => $this->input->post('name'), 'description' => $this->input->post('desc'), 'logo' => $file_on_server, 'is_active' => 1);
if ($this->brand->create($values)) {
$this->session->set_flashdata('message', 'New Brand added successfully');
} else {
$this->session->set_flashdata('errormessage', 'Oops! Something went wrong!!');
}
redirect(base_url() . 'brands/');
}
$this->load->helper('form');
$this->load->view('includes/header', array('title' => 'Add Brand'));
$this->load->view('brand/new_brand');
$this->load->view('includes/footer');
}
示例3: testCreatedCustomerWithSpecifiedRef
public function testCreatedCustomerWithSpecifiedRef()
{
$customerCreateEvent = new CustomerCreateOrUpdateEvent(1, "thelia", "thelia", "street address 1", "street address 2", "street address 3", "0102030405", "0607080910", "63000", "clermont-ferrand", 64, sprintf("%s@thelia.fr", uniqid()), uniqid(), 1, 0, 0, 0, 'My super company', 'testRef');
/** @var Customer $customerAction */
$customerAction = $this->customerAction;
$customerAction->create($customerCreateEvent, null, $this->getMockEventDispatcher());
$customerCreated = $customerCreateEvent->getCustomer();
$this->assertInstanceOf("Thelia\\Model\\Customer", $customerCreated, "new customer created must be an instance of Thelia\\Model\\Customer");
$this->assertFalse($customerCreated->isNew());
$this->assertEquals($customerCreateEvent->getFirstname(), $customerCreated->getFirstname());
$this->assertEquals($customerCreateEvent->getLastname(), $customerCreated->getLastname());
$this->assertEquals($customerCreateEvent->getTitle(), $customerCreated->getTitleId());
$this->assertEquals($customerCreateEvent->getEmail(), $customerCreated->getEmail());
$this->assertEquals($customerCreateEvent->getReseller(), $customerCreated->getReseller());
$this->assertEquals($customerCreateEvent->getSponsor(), $customerCreated->getSponsor());
$this->assertEquals($customerCreateEvent->getDiscount(), $customerCreated->getDiscount());
$this->assertEquals($customerCreateEvent->getRef(), $customerCreated->getRef());
$addressCreated = $customerCreated->getDefaultAddress();
$this->assertInstanceOf("Thelia\\Model\\Address", $addressCreated);
$this->assertEquals($customerCreateEvent->getFirstname(), $addressCreated->getFirstname());
$this->assertEquals($customerCreateEvent->getLastname(), $addressCreated->getLastname());
$this->assertEquals($customerCreateEvent->getTitle(), $addressCreated->getTitleId());
$this->assertEquals($customerCreateEvent->getAddress1(), $addressCreated->getAddress1());
$this->assertEquals($customerCreateEvent->getAddress2(), $addressCreated->getAddress2());
$this->assertEquals($customerCreateEvent->getAddress3(), $addressCreated->getAddress3());
$this->assertEquals($customerCreateEvent->getZipcode(), $addressCreated->getZipcode());
$this->assertEquals($customerCreateEvent->getCity(), $addressCreated->getCity());
$this->assertEquals($customerCreateEvent->getCountry(), $addressCreated->getCountryId());
$this->assertEquals($customerCreateEvent->getPhone(), $addressCreated->getPhone());
$this->assertEquals($customerCreateEvent->getCellphone(), $addressCreated->getCellphone());
$this->assertEquals($customerCreateEvent->getCompany(), $addressCreated->getCompany());
}
示例4: generateHash
function generateHash($password)
{
if (defined("CRYPT_BLOWFISH") && CRYPT_BLOWFISH) {
$salt = '$2y$11$' . substr(md5(uniqid(rand(), true)), 0, 22);
return crypt($password, $salt);
}
}
示例5: __construct
public function __construct()
{
$configFile = __DIR__ . '/../config.yml';
$value = Yaml::parse(file_get_contents($configFile));
$ariAddress = $value['examples']['client']['ari_address'];
$dialString = $value['examples']['dial_example']['dial_string'];
$logger = new \Zend\Log\Logger();
$logWriter = new \Zend\Log\Writer\Stream("php://output");
$logger->addWriter($logWriter);
//$filter = new \Zend\Log\Filter\SuppressFilter(true);
$filter = new \Zend\Log\Filter\Priority(\Zend\Log\Logger::NOTICE);
$logWriter->addFilter($filter);
// Connect to the ARI server
$this->client = new Phparia($logger);
$this->client->connect($ariAddress);
$this->client->getAriClient()->onConnect(function () use($dialString) {
try {
$this->client->channels()->createChannel($dialString, null, null, null, null, $this->client->getStasisApplicationName(), 'dialed', '8185551212', 30, null, null, array('MYVARIABLE' => 'value'));
} catch (\phparia\Exception\ServerException $e) {
$this->log($e->getMessage());
}
});
// Listen for the stasis start
$this->client->onStasisStart(function (StasisStart $event) use($dialString) {
if (count($event->getArgs()) > 0 && $event->getArgs()[0] === 'dialed') {
$this->log('Detected outgoing call with variable MYVARIABLE=' . $event->getChannel()->getVariable('MYVARIABLE')->getValue());
// Put the new channel in a bridge
$channel = $event->getChannel();
$this->bridge = $this->client->bridges()->createBridge(uniqid(), 'dtmf_events, mixing', 'dial_example_bridge');
$this->bridge->addChannel($channel->getId());
}
});
$this->client->run();
}
示例6: start
/**
* 开启事务
* @return Database_Driver_MySQLI_Transaction
*/
public function start()
{
if ($this->id) {
throw new Exception('transaction has started');
}
# 推动连接主数据库
$this->db_driver->connect(true);
# 获取连接ID
$this->_connection_id = $this->db_driver->connection_id();
# 获取唯一ID
$this->id = uniqid('TaId_' . rand());
if (isset(Database_Driver_MySQLI_Transaction::$transactions[$this->_connection_id])) {
# 已存在事务,则该事务为子事务
if ($this->_set_save_point()) {
//保存事务点
Database_Driver_MySQLI_Transaction::$transactions[$this->_connection_id][$this->id] = true;
} else {
$this->id = null;
# 开启事务失败。
throw new Exception('start sub transaction error');
}
} else {
# 开启新事务
$this->_query('SET AUTOCOMMIT=0;');
if (true === $this->_query('START TRANSACTION;')) {
# 如果没有建立到当前主服务器的连接,该操作会隐式的建立
Database_Driver_MySQLI_Transaction::$transactions[$this->_connection_id] = array($this->id => true);
} else {
$this->id = null;
# 开启事务失败。
throw new Exception('start transaction error');
}
}
return true;
}
示例7: KT_CaptchaImage
/**
* Constructor.
* @param string name to use to store in session the captcha string;
* @return nothing
*/
function KT_CaptchaImage($name)
{
$this->name = 'KT_captcha_' . $name;
$this->text = $this->getRandomText();
$this->filename = substr(md5(uniqid(rand(), true)), 0, 8) . '.png';
$this->lib = $GLOBALS['KT_prefered_image_lib'];
}
示例8: smarty_block_form
function smarty_block_form($params, $content, &$smarty, $repeat)
{
if (!empty($content)) {
// set default output vars
$data = array('search_id' => FALSE, 'submit_token_id' => FALSE, 'class' => '', 'content' => $content, 'method' => 'post');
$modules = $smarty->getTemplateVars('modules');
if (!empty($modules)) {
$module = '';
$prefix = 'module=';
foreach ($modules as $mod) {
$module .= $prefix . $mod . '&';
$prefix = 'sub' . $prefix;
}
}
if (isset($params['target'])) {
$data['action'] = $params['target'];
} else {
$access = AccessObject::Instance();
$pid = $access->getPermission($modules, $params['controller'], $params['action']);
$data['action'] = '/?pid=' . $pid . '&' . $module . 'controller=' . $params['controller'] . '&action=' . $params['action'];
}
if (isset($params['subfunction'])) {
$data['action'] .= '&subfunction=' . $params['subfunction'];
if (isset($params['subfunctionaction'])) {
$data['action'] .= '&subfunctionaction=' . $params['subfunctionaction'];
}
}
if (isset($params['id'])) {
$data['action'] .= '&id=' . $params['id'];
}
foreach ($params as $name => $value) {
if ($name[0] === '_') {
$data['action'] .= '&' . substr($name, 1) . '=' . $value;
}
}
if (isset($params['additional_data'])) {
foreach ($params['additional_data'] as $name => $value) {
$data['action'] .= '&' . $name . '=' . $value;
}
}
if (isset($params['class'])) {
$data['class'] = $params['class'];
}
$data['original_action'] = $smarty->getTemplateVars('action');
if (isset($_GET['search_id'])) {
$data['search_id'] = $_GET['search_id'];
}
// there are some instances where we don't want the submit token
if (strtoupper($params['submit_token']) !== 'FALSE') {
$data['submit_token_id'] = uniqid();
$_SESSION['submit_token'][$data['submit_token_id']] = TRUE;
}
$data['display_tags'] = !isset($params['notags']);
if (isset($params['form_id'])) {
$data['form_id'] = $params['form_id'];
}
// fetch smarty plugin template
return smarty_plugin_template($smarty, $data, 'block.form');
}
}
示例9: preProcessing
public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
{
$params = $compiler->getCompiledParams($params);
$parsedParams = array();
if (!isset($params['*'])) {
$params['*'] = array();
}
foreach ($params['*'] as $param => $defValue) {
if (is_numeric($param)) {
$param = $defValue;
$defValue = null;
}
$param = trim($param, '\'"');
if (!preg_match('#^[a-z0-9_]+$#i', $param)) {
throw new Dwoo_Compilation_Exception($compiler, 'Function : parameter names must contain only A-Z, 0-9 or _');
}
$parsedParams[$param] = $defValue;
}
$params['name'] = substr($params['name'], 1, -1);
$params['*'] = $parsedParams;
$params['uuid'] = uniqid();
$compiler->addTemplatePlugin($params['name'], $parsedParams, $params['uuid']);
$currentBlock =& $compiler->getCurrentBlock();
$currentBlock['params'] = $params;
return '';
}
示例10: testGetValidateHash
public function testGetValidateHash()
{
$password = uniqid();
$hash = $this->_model->getHash($password);
$this->assertTrue(is_string($hash));
$this->assertTrue($this->_model->validateHash($password, $hash));
}
示例11: renderAudioPlayer
/**
* Renders audio player for the blog
*
* @since 5.0
* @access public
* @param string
* @return
*/
public function renderAudioPlayer($uri, $options = array())
{
// Merge the options with the default options
$options = array_replace_recursive(self::$defaultAudioOptions, $options);
// Generate a random uid
$uniqid = uniqid();
$uid = 'audio-' . EBMM::getHash($uri . $uniqid);
// Url to the audio
$url = $this->normalizeURI($uri);
// Get the track if there is no track provided
if (!$options['track']) {
$options['track'] = basename($url);
}
// Set a default artist if artist isn't set
if (!$options['artist']) {
$options['artist'] = JText::_('COM_EASYBLOG_BLOCKS_AUDIO_ARTIST');
}
$template = EB::template();
$template->set('uid', $uid);
$template->set('showTrack', $options['showTrack']);
$template->set('showDownload', $options['showDownload']);
$template->set('showArtist', $options['showArtist']);
$template->set('autoplay', $options['autoplay']);
$template->set('loop', $options['loop']);
$template->set('artist', $options['artist']);
$template->set('track', $options['track']);
$template->set('url', $url);
$output = $template->output('site/blogs/blocks/audio');
return $output;
}
示例12: generateFormkey
/**
* Generate the form key based on IP address
*
* @return string md5sum of IP address + unique number
*/
private function generateFormkey()
{
$ip = $_SERVER['REMOTE_ADDR'];
// mt_rand() is better than rand()
$uniqid = uniqid(mt_rand(), true);
return md5($ip . $uniqid);
}
示例13: submit
function submit()
{
//Check required Fields
$missing = false;
if (!isset($_POST["sql"]) || strlen($_POST["sql"]) == 0) {
$missing = true;
}
if ($missing) {
$this->res->success = false;
$this->res->message = "missing required field!";
return null;
}
//get vars
$sql = $_POST["sql"];
$schema_id = $this->params['schema_id'];
$schema = Doo::db()->getOne('Schemata', array('where' => 'id = ' . $schema_id));
$async = isset($_POST['async']) ? $_POST['async'] : 0;
$coord_name = isset($_POST['coord_name']) ? $_POST['coord_name'] : null;
$query_id = isset($_POST["query_id"]) ? $_POST["query_id"] : strtoupper(md5(uniqid(rand(), true)));
//init
$shard_query = new ShardQuery($schema->schema_name);
//error!
if (!empty($shard_query->errors)) {
//return
$this->res->message = $shard_query->errors;
$this->res->success = false;
return null;
}
//set async
$shard_query->async = $async == true ? true : false;
//set coord shard
if (isset($coord_name)) {
$shard_query->set_coordinator($coord_name);
}
//execute query
$stmt = $shard_query->query($sql);
//error!
if (!$stmt && !empty($shard_query->errors)) {
//return
$this->res->message = $shard_query->errors;
$this->res->success = false;
return null;
}
//empty results
if ($stmt == null && empty($shard_query->errors)) {
$this->res->data = array();
}
//build data
if (!is_int($stmt)) {
$this->res->data = $this->json_format($shard_query, $stmt);
$shard_query->DAL->my_free_result($stmt);
} else {
//save job_id
$this->res->data = $stmt;
}
//save message
$this->res->message = $query_id;
//return
$this->res->success = true;
}
示例14: get_valid_layout
function get_valid_layout($layout = array())
{
// parse
$layout = wp_parse_args($layout, array('key' => uniqid(), 'name' => '', 'label' => '', 'display' => 'block', 'sub_fields' => array(), 'min' => '', 'max' => ''));
// return
return $layout;
}
示例15: query
/**
* execute query - show be regarded as private to insulate the rest of
* the application from sql differences
* @access private
*/
function query($sql)
{
global $CONF;
if (is_null($this->dblink)) {
$this->_connect();
}
//been passed more parameters? do some smart replacement
if (func_num_args() > 1) {
//query contains ? placeholders, but it's possible the
//replacement string have ? in too, so we replace them in
//our sql with something more unique
$q = md5(uniqid(rand(), true));
$sql = str_replace('?', $q, $sql);
$args = func_get_args();
for ($i = 1; $i <= count($args); $i++) {
$sql = preg_replace("/{$q}/", "'" . preg_quote(mysql_real_escape_string($args[$i])) . "'", $sql, 1);
}
//we shouldn't have any $q left, but it will help debugging if we change them back!
$sql = str_replace($q, '?', $sql);
}
$this->dbresult = mysql_query($sql, $this->dblink);
if (!$this->dbresult) {
die("Query failure: " . mysql_error() . "<br />{$sql}");
}
return $this->dbresult;
}