本文整理汇总了PHP中time函数的典型用法代码示例。如果您正苦于以下问题:PHP time函数的具体用法?PHP time怎么用?PHP time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: responseMsg
public function responseMsg()
{
//get post data, May be due to the different environments
$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
//extract post data
if (!empty($postStr)) {
/* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
the best way is to check the validity of xml by yourself */
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
$fromUsername = $postObj->FromUserName;
$toUsername = $postObj->ToUserName;
$keyword = trim($postObj->Content);
$time = time();
$textTpl = "<xml>\n\t\t\t\t\t\t\t<ToUserName><![CDATA[%s]]></ToUserName>\n\t\t\t\t\t\t\t<FromUserName><![CDATA[%s]]></FromUserName>\n\t\t\t\t\t\t\t<CreateTime>%s</CreateTime>\n\t\t\t\t\t\t\t<MsgType><![CDATA[%s]]></MsgType>\n\t\t\t\t\t\t\t<Content><![CDATA[%s]]></Content>\n\t\t\t\t\t\t\t<FuncFlag>0</FuncFlag>\n\t\t\t\t\t\t\t</xml>";
if (!empty($keyword)) {
$msgType = "text";
$contentStr = "Welcome to wechat world!";
$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
echo $resultStr;
} else {
echo "Input something...";
}
} else {
echo "";
exit;
}
}
示例2: save
/**
* Save an uploaded file to a new location.
*
* @param mixed name of $_FILE input or array of upload data
* @param string new filename
* @param string new directory
* @param integer chmod mask
* @return string full path to new file
*/
public static function save($file, $filename = NULL, $directory = NULL, $chmod = 0755)
{
// Load file data from FILES if not passed as array
$file = is_array($file) ? $file : $_FILES[$file];
if ($filename === NULL) {
// Use the default filename, with a timestamp pre-pended
$filename = time() . $file['name'];
}
// Remove spaces from the filename
$filename = preg_replace('/\\s+/', '_', $filename);
if ($directory === NULL) {
// Use the pre-configured upload directory
$directory = WWW_ROOT . 'files/';
}
// Make sure the directory ends with a slash
$directory = rtrim($directory, '/') . '/';
if (!is_dir($directory)) {
// Create the upload directory
mkdir($directory, 0777, TRUE);
}
//if ( ! is_writable($directory))
//throw new exception;
if (is_uploaded_file($file['tmp_name']) and move_uploaded_file($file['tmp_name'], $filename = $directory . $filename)) {
if ($chmod !== FALSE) {
// Set permissions on filename
chmod($filename, $chmod);
}
//$all_file_name = array(FILE_INFO => $filename);
// Return new file path
return $filename;
}
return FALSE;
}
示例3: getAge
public static function getAge($unix_timestamp)
{
$t = time();
$age = $unix_timestamp < 0 ? $t + $unix_timestamp * -1 : $t - $unix_timestamp;
$year = 60 * 60 * 24 * 365;
return floor($age / $year);
}
示例4: flickr_faves_add_fave
function flickr_faves_add_fave(&$viewer, &$photo, $date_faved = 0)
{
if (!$date_faved) {
$date_faved = time();
}
$cluster_id = $viewer['cluster_id'];
$fave = array('user_id' => $viewer['id'], 'photo_id' => $photo['id'], 'owner_id' => $photo['user_id'], 'date_faved' => $date_faved);
$insert = array();
foreach ($fave as $k => $v) {
$insert[$k] = AddSlashes($v);
}
$rsp = db_insert_users($cluster_id, 'FlickrFaves', $insert);
if (!$rsp['ok'] && $rsp['error_code'] != 1062) {
return $rsp;
}
# now update the photo owner side of things
$owner = users_get_by_id($photo['user_id']);
$cluster_id = $owner['cluster_id'];
$fave = array('user_id' => $owner['id'], 'photo_id' => $photo['id'], 'viewer_id' => $viewer['id']);
$insert = array();
foreach ($fave as $k => $v) {
$insert[$k] = AddSlashes($v);
}
$rsp = db_insert_users($cluster_id, 'FlickrFavesUsers', $insert);
if (!$rsp['ok'] && $rsp['error_code'] != 1062) {
return $rsp;
}
# TO DO: index/update the photo in solr and insert $viewer['id']
# into the faved_by column (20111123/straup)
return okay();
}
示例5: generateSecurekey
/**
*
* @ORM\PrePersist
*/
public function generateSecurekey()
{
$generator = new SecureRandom();
$random = $generator->nextBytes(150);
$securekey = md5($random . time());
$this->setSecurekey($securekey);
}
示例6: login
/**
* 登陆,如果失败,返回失败原因(用户名或者密码不正确),如果成功,返回用户信息,
* 附带返回系统服务器时间戳
*/
public function login()
{
//查user表
$User = M('User');
check_error($User);
$user = $User->field(array('id' => 'userId', 'username' => 'userName', 'name', 'role_id' => 'roleId', 'role'))->where(array('username' => safe_post_param('username'), '_string' => "`password`=MD5('" . safe_post_param('password') . "')"))->find();
if (!empty($user)) {
//根据权限查菜单
$Menu = M('Menu');
check_error($Menu);
$menu = $Menu->join('`role_privilege` on `menu`.`id`=`role_privilege`.`menu_id`')->join('`user` on `user`.`role_id`=`role_privilege`.`role_id`')->field(array('`menu`.`id`', 'level', 'label', 'icon', 'widget', 'show', 'big_icon'))->where("`user`.`id`='" . $user['userId'] . "'")->order('`level` ASC')->select();
check_error($Menu);
//保存session
session('logined', true);
session('user', $user);
session('menu', $menu);
//设置返回数据
$data = array();
$data['serverTime'] = time();
$data['user'] = $user;
$data['menu'] = $menu;
//保存日志
R('Log/adduserlog', array('登录', '登录成功', '成功'));
//返回结果:用户数据+服务器时间
return_value_json(true, 'data', $data);
} else {
//保存日志
R('Log/adduserlog', array('登录', '登录失败:用户名或者密码不正确', '失败:权限不够', '用户名:' . safe_post_param('username')));
return_value_json(false, 'msg', '用户名或者密码不正确');
}
}
示例7: collectData
public function collectData(array $param)
{
$html = $this->file_get_html('http://www.maliki.com/') or $this->returnError('Could not request Maliki.', 404);
$count = 0;
$latest = 1;
$latest_title = "";
$latest = $html->find('div.conteneur_page a', 1)->href;
$latest_title = $html->find('div.conteneur_page img', 0)->title;
function MalikiExtractContent($url)
{
$html2 = $this->file_get_html($url);
$text = 'http://www.maliki.com/' . $html2->find('img', 0)->src;
$text = '<img alt="" src="' . $text . '"/><br>' . $html2->find('div.imageetnews', 0)->plaintext;
return $text;
}
$item = new \Item();
$item->uri = 'http://www.maliki.com/' . $latest;
$item->title = $latest_title;
$item->timestamp = time();
$item->content = MalikiExtractContent($item->uri);
$this->items[] = $item;
foreach ($html->find('div.boite_strip') as $element) {
if (!empty($element->find('a', 0)->href) and $count < 3) {
$item = new \Item();
$item->uri = 'http://www.maliki.com/' . $element->find('a', 0)->href;
$item->title = $element->find('img', 0)->title;
$item->timestamp = strtotime(str_replace('/', '-', $element->find('span.stylepetit', 0)->innertext));
$item->content = MalikiExtractContent($item->uri);
$this->items[] = $item;
$count++;
}
}
}
示例8: session_init
/**
* Initialize session.
* @param boolean $keepopen keep session open? The default is
* to close the session after $_SESSION has been populated.
* @uses $_SESSION
*/
function session_init($keepopen = false)
{
$settings = new phpVBoxConfigClass();
// Sessions provided by auth module?
if (@$settings->auth->capabilities['sessionStart']) {
call_user_func(array($settings->auth, $settings->auth->capabilities['sessionStart']), $keepopen);
return;
}
// No session support? No login...
if (@$settings->noAuth || !function_exists('session_start')) {
global $_SESSION;
$_SESSION['valid'] = true;
$_SESSION['authCheckHeartbeat'] = time();
$_SESSION['admin'] = true;
return;
}
// start session
session_start();
// Session is auto-started by PHP?
if (!ini_get('session.auto_start')) {
ini_set('session.use_trans_sid', 0);
ini_set('session.use_only_cookies', 1);
// Session path
if (isset($settings->sessionSavePath)) {
session_save_path($settings->sessionSavePath);
}
session_name(isset($settings->session_name) ? $settings->session_name : md5('phpvbx' . $_SERVER['DOCUMENT_ROOT'] . $_SERVER['HTTP_USER_AGENT']));
session_start();
}
if (!$keepopen) {
session_write_close();
}
}
示例9: smarty_validate_criteria_isCCExpDate
/**
* test if a value is a valid credit card expiration date
*
* @param string $value the value being tested
* @param boolean $empty if field can be empty
* @param array params validate parameter values
* @param array formvars form var values
*/
function smarty_validate_criteria_isCCExpDate($value, $empty, &$params, &$formvars)
{
if (strlen($value) == 0) {
return $empty;
}
if (!preg_match('!^(\\d+)\\D+(\\d+)$!', $value, $_match)) {
return false;
}
$_month = $_match[1];
$_year = $_match[2];
if (strlen($_year) == 2) {
$_year = substr(date('Y', time()), 0, 2) . $_year;
}
$_month = (int) $_month;
$_year = (int) $_year;
if ($_month < 1 || $_month > 12) {
return false;
}
if (date('Y', time()) > $_year) {
return false;
}
if (date('Y', time()) == $_year && date('m', time()) > $_month) {
return false;
}
return true;
}
示例10: format_time
public function format_time($timestamp, $date_only = false, $date_format = null, $time_format = null, $time_only = false, $no_text = false)
{
global $forum_date_formats, $forum_time_formats;
if ($timestamp == '') {
return __('Never');
}
$diff = ($this->feather->user->timezone + $this->feather->user->dst) * 3600;
$timestamp += $diff;
$now = time();
if (is_null($date_format)) {
$date_format = $forum_date_formats[$this->feather->user->date_format];
}
if (is_null($time_format)) {
$time_format = $forum_time_formats[$this->feather->user->time_format];
}
$date = gmdate($date_format, $timestamp);
$today = gmdate($date_format, $now + $diff);
$yesterday = gmdate($date_format, $now + $diff - 86400);
if (!$no_text) {
if ($date == $today) {
$date = __('Today');
} elseif ($date == $yesterday) {
$date = __('Yesterday');
}
}
if ($date_only) {
return $date;
} elseif ($time_only) {
return gmdate($time_format, $timestamp);
} else {
return $date . ' ' . gmdate($time_format, $timestamp);
}
}
示例11: welcomeOp
/**
* 欢迎页面
*/
public function welcomeOp()
{
/**
* 管理员信息
*/
$model_admin = Model('admin');
$tmp = $this->getAdminInfo();
$condition['admin_id'] = $tmp['id'];
$admin_info = $model_admin->infoAdmin($condition);
$admin_info['admin_login_time'] = date('Y-m-d H:i:s', $admin_info['admin_login_time'] == '' ? time() : $admin_info['admin_login_time']);
/**
* 系统信息
*/
$version = C('version');
$setup_date = C('setup_date');
$statistics['os'] = PHP_OS;
$statistics['web_server'] = $_SERVER['SERVER_SOFTWARE'];
$statistics['php_version'] = PHP_VERSION;
$statistics['sql_version'] = Db::getServerInfo();
$statistics['shop_version'] = $version;
$statistics['setup_date'] = substr($setup_date, 0, 10);
// 运维舫 c extension
try {
$r = new ReflectionExtension('shopnc');
$statistics['php_version'] .= ' / ' . $r->getVersion();
} catch (ReflectionException $ex) {
}
Tpl::output('statistics', $statistics);
Tpl::output('admin_info', $admin_info);
Tpl::showpage('welcome');
}
示例12: getData
protected function getData($nowPage,$pageSize)
{/*{{{*/
$dataList = $this->prepareData($nowPage, $pageSize);
$res = array();
foreach ($dataList as $data)
{
$provinceKey = Area::getProvKeyByName($data['prov']);
$tempData = array();
$tempData['item']['key'] = $data['prov'].$data['dname'].'医院';
$tempData['item']['url'] = 'http://www.haodf.com/jibing/'.$data['dkey'].'/yiyuan.htm?province='.$provinceKey;
$tempData['item']['showurl'] = 'www.haodf.com';
$tempData['item']['title'] = $data['prov'].$data['dname']."推荐医院_好大夫在线";
$tempData['item']['pagesize'] = rand(58, 62).'K';
$tempData['item']['date'] = date('Y-m-d', time());
$tempData['item']['content1'] = "根据".$data['diseasevote']."位".$data['dname']."患者投票得出的医院排行";
$tempData['item']['link'] = $tempData['item']['url'];
foreach ($data['formdata'] as $formData)
{
$tempData['item'][] = $formData;
unset($formData);
}
$res[] = $tempData;
unset($data);
}
return $res;
}/*}}}*/
示例13: callback
public function callback()
{
//$_REQUEST['MerchantTradeNo'] = "65";
$this->load->model('checkout/order');
//$query_url = "https://payment.allpay.com.tw/Cashier/QueryTradeInfo";
$query_url = "https://payment.allpay.com.tw/Cashier/QueryTradeInfo";
$timestamp = time();
$hash_iv = $this->config->get('allpay_credit18_iv_key');
$hash_key = $this->config->get('allpay_credit18_hash_key');
$order_id = $_REQUEST['MerchantTradeNo'];
$mer_id = $this->config->get('allpay_credit18_account');
$order_finish_statu = $this->config->get('allpay_credit18_order_finish_status_id');
$input_array = array("MerchantID" => $mer_id, "MerchantTradeNo" => $order_id, "TimeStamp" => $timestamp);
ksort($input_array);
$checkvalue = "HashKey={$hash_key}&" . urldecode(http_build_query($input_array)) . "&HashIV={$hash_iv}";
$checkvalue = strtolower(urlencode($checkvalue));
$checkvalue = md5($checkvalue);
$input_array["CheckMacValue"] = $checkvalue;
$post_data = http_build_query($input_array);
$result = $this->curl_work($query_url, "POST", $post_data);
parse_str($result["web_info"], $query_result);
$order_info = $this->model_checkout_order->getOrder($order_id);
$system_total_amt = intval(round($order_info['total']));
if ($query_result["TradeStatus"] == "1" && $query_result["TradeAmt"] == $system_total_amt) {
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '{$order_finish_statu}', date_modified = NOW() WHERE order_id = '" . $order_id . "'");
}
}
示例14: collectData
public function collectData(array $param)
{
$page = 0;
$tags = '';
if (isset($param['p'])) {
$page = (int) preg_replace("/[^0-9]/", '', $param['p']);
$page = $page - 1;
$page = $page * 50;
}
if (isset($param['t'])) {
$tags = urlencode($param['t']);
}
$html = $this->file_get_html("http://mspabooru.com/index.php?page=post&s=list&tags={$tags}&pid={$page}") or $this->returnError('Could not request Mspabooru.', 404);
foreach ($html->find('div[class=content] span') as $element) {
$item = new \Item();
$item->uri = 'http://mspabooru.com/' . $element->find('a', 0)->href;
$item->postid = (int) preg_replace("/[^0-9]/", '', $element->getAttribute('id'));
$item->timestamp = time();
$item->thumbnailUri = $element->find('img', 0)->src;
$item->tags = $element->find('img', 0)->getAttribute('alt');
$item->title = 'Mspabooru | ' . $item->postid;
$item->content = '<a href="' . $item->uri . '"><img src="' . $item->thumbnailUri . '" /></a><br>Tags: ' . $item->tags;
$this->items[] = $item;
}
}
示例15: testSetRefreshToken
/** @dataProvider provideStorage */
public function testSetRefreshToken(RefreshTokenInterface $storage)
{
if ($storage instanceof NullStorage) {
$this->markTestSkipped('Skipped Storage: ' . $storage->getMessage());
return;
}
// assert token we are about to add does not exist
$token = $storage->getRefreshToken('refreshtoken');
$this->assertFalse($token);
// add new token
$expires = time() + 20;
$success = $storage->setRefreshToken('refreshtoken', 'oauth_test_client', '1', $expires, 'supportedscope1 supportedscope2');
$this->assertTrue($success);
$token = $storage->getRefreshToken('refreshtoken');
$this->assertNotNull($token);
$this->assertArrayHasKey('refresh_token', $token);
$this->assertArrayHasKey('client_id', $token);
$this->assertArrayHasKey('user_id', $token);
$this->assertArrayHasKey('expires', $token);
$this->assertEquals($token['refresh_token'], 'refreshtoken');
$this->assertEquals($token['client_id'], 'oauth_test_client');
$this->assertEquals($token['user_id'], '1');
# reference from client
$this->assertEquals($token['expires'], $expires);
# should be expreRefreshToken?
$this->assertTrue($storage->unsetRefreshToken('refreshtoken'));
}