本文整理汇总了PHP中Safe::setcookie方法的典型用法代码示例。如果您正苦于以下问题:PHP Safe::setcookie方法的具体用法?PHP Safe::setcookie怎么用?PHP Safe::setcookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Safe
的用法示例。
在下文中一共展示了Safe::setcookie方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_cookie
/**
* set a permanent cookie
*
* @param string cookie name
* @param string cookie value
*/
public static function set_cookie($name, $value)
{
global $context;
// assign the cookie to this instance of yacs
Safe::setcookie($name, $value, time() + 60 * 60 * 24 * 500, $context['url_to_root']);
// also set cookies used in leading index.php
if ($home = getenv('YACS_HOME')) {
Safe::setcookie($name, $value, time() + 60 * 60 * 24 * 500, $home . '/');
}
if ($context['url_to_root'] == '/yacs/') {
Safe::setcookie($name, $value, time() + 60 * 60 * 24 * 500, '/');
}
}
示例2: elseif
Logger::error(i18n::s('This page has no overlay'));
// not a valid poll
} elseif (!@count($overlay->attributes['answers'])) {
Logger::error(i18n::s('Not a valid poll'));
// not a valid vote
} elseif ($vote < 1 || $vote > @count($overlay->attributes['answers'])) {
Logger::error(i18n::s('Not a valid vote'));
// a vote has already been registered
} elseif (isset($_COOKIE['poll_' . $item['id']])) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You have already voted'));
// record the vote
} else {
// set a cookie to remember the vote for 100 days
if ($id && $vote) {
Safe::setcookie('poll_' . $item['id'], $vote, time() + 60 * 60 * 24 * 100, $context['url_to_root']);
}
// increment answers
$vote--;
list($label, $count) = $overlay->attributes['answers'][$vote];
$overlay->attributes['answers'][$vote] = array($label, $count + 1);
// supports up to two levels arrays
foreach ($overlay->attributes as $name => $value) {
if (is_array($value)) {
foreach ($value as $sub_name => $sub_value) {
$overlay->attributes[$name][$sub_name] = str_replace('\\', '\\\\', $sub_value);
}
} else {
$overlay->attributes[$name] = str_replace('\\', '\\\\', $value);
}
}
示例3: time
<?php
/**
* break a session
*
* @author Bernard Paques
* @reference
* @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
*/
// common definitions and initial processing
include_once '../shared/global.php';
// if it was a HEAD request, stop here
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'HEAD') {
return;
}
// clear permanent name
Safe::setcookie('surfer_name', '', time() + 60 * 60 * 24 * 500, '/');
// destroy surfer session
Surfer::reset();
// redirect to another page
if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] && !preg_match('/login\\.php/i', $_SERVER['HTTP_REFERER'])) {
Safe::redirect($_SERVER['HTTP_REFERER']);
} else {
Safe::redirect($context['url_to_home'] . $context['url_to_root']);
}
示例4: time
// give a four
$context['text'] .= '<div style="float: left;"><input name="rating" type="radio" value="4" onclick="$(\'#main_form\').submit()" /> ' . i18n::s('Good') . ' </div> ';
// give a three
$context['text'] .= '<div style="float: left;"><input name="rating" type="radio" value="3" onclick="$(\'#main_form\').submit()" /> ' . i18n::s('Average') . ' </div> ';
// give a two
$context['text'] .= '<div style="float: left;"><input name="rating" type="radio" value="2" onclick="$(\'#main_form\').submit()" /> ' . i18n::s('Poor') . ' </div> ';
// give a one
$context['text'] .= '<div style="float: left;"><input name="rating" type="radio" value="1" onclick="$(\'#main_form\').submit()" /> ' . i18n::s('Forget it') . ' </div> ';
$context['text'] .= '<br style="clear: left;" />';
// end of the form
$context['text'] .= '</div></form>';
// record the rating
} else {
// set a cookie to remember the rating for 100 days
if ($rating) {
Safe::setcookie('rating_' . $item['id'], $rating, time() + 60 * 60 * 24 * 100, $context['url_to_root']);
}
// update the database
Articles::rate($item['id'], $rating);
// touch the related anchor
if (is_object($anchor)) {
$anchor->touch('article:update', $item['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y');
}
// clear the cache
Articles::clear($item);
// return from rating
if (!headers_sent()) {
// go back to page referring to here
if (isset($_REQUEST['referer'])) {
Safe::redirect($_REQUEST['referer']);
} else {
示例5: elseif
$context['page_title'] = i18n::s('Validate your e-mail address');
// stop crawlers
if (Surfer::is_crawler()) {
Safe::header('Status: 401 Unauthorized', TRUE, 401);
Logger::error(i18n::s('You are not allowed to perform this operation.'));
// not found
} elseif (!isset($item['id'])) {
include '../error.php';
// bad handle
} elseif ($id != $item['handle']) {
include '../error.php';
} elseif (Users::validate($item['id'])) {
// congratulations
$context['text'] .= sprintf(i18n::s('<p>%s,</p><p>Your e-mail address has been validated, and you are now an active member of this community.</p>'), ucfirst($item['nick_name']));
// set permanent name shown from top level
Safe::setcookie('surfer_name', $item['nick_name'], time() + 60 * 60 * 24 * 500, '/');
// save surfer profile in session context
Surfer::set($item);
// follow-up commands
$follow_up = i18n::s('Where do you want to go now?');
$menu = array();
$menu = array_merge($menu, array(Users::get_permalink($item) => i18n::s('My profile')));
$menu = array_merge($menu, array($context['url_to_root'] => i18n::s('Front page')));
$follow_up .= Skin::build_list($menu, 'menu_bar');
$context['text'] .= Skin::build_block($follow_up, 'bottom');
// failed operation
} else {
$context['text'] .= '<p>' . i18n::s('Your e-mail address has not been validated.') . "</p>\n";
}
// render the skin
render_skin();
示例6: array
// extra panel
//
// user profile aside
$context['components']['profile'] = Skin::build_profile($user, 'extra');
// navigation links, in an extra box
$links = array();
$links = array_merge($links, array($context['url_to_root'] => i18n::s('Front page')));
$links = array_merge($links, array('sections/' => i18n::s('Site map')));
$links = array_merge($links, array('users/' => i18n::s('People')));
$links = array_merge($links, array('categories/' => i18n::s('Categories')));
$links = array_merge($links, array('search.php' => i18n::s('Search')));
$context['components']['boxes'] .= Skin::build_box(i18n::s('Navigate'), Skin::build_list($links, 'compact'), 'boxes');
// failed authentication
} else {
// set permanent name shown from top level
Safe::setcookie('surfer_name', preg_replace('/(@.+)$/', '', $name), time() + 60 * 60 * 24 * 500, '/');
// reset the current session
Surfer::reset();
// share status
Logger::error(i18n::s('Failed authentication'), FALSE);
// help surfer to recover
if ($items =& Users::search($name, 1.0, 7, 'password')) {
// display candidate profiles
if (is_array($items)) {
$items =& Skin::build_list($items, 'decorated');
}
$context['text'] .= Skin::build_box(i18n::s('Have you lost your password?'), $items);
}
// ask for support
$context['text'] .= Skin::build_box(i18n::s('Do you need more help?'), '<p>' . sprintf(i18n::s('Use the %s to ask for help'), Skin::build_link('query.php', i18n::s('query form'), 'shortcut')) . '</p>');
}
示例7: put
/**
* put an updated user profile in the database
*
* If present, only the password is changed. Or other fields except the password are modified.
*
* To change a password, set fields 'id', 'password' and 'confirm'
*
* @param array an array of fields
* @return TRUE on success, FALSE otherwise
*
* @see users/edit.php
* @see users/password.php
* @see users/select_avatar.php
**/
public static function put(&$fields)
{
global $context;
// load the record
$item = Users::get($fields['id']);
if (!isset($item['id']) || !$item['id']) {
Logger::error(i18n::s('No item has the provided id.'));
return FALSE;
}
// remember who is changing this record
Surfer::check_default_editor($fields);
// if a password change
if (isset($fields['password'])) {
// ensure that the password has been provided twice
if (!isset($fields['confirm']) || $fields['confirm'] != $fields['password']) {
Logger::error(i18n::s('New password has to be confirmed.'));
return FALSE;
}
// hash password, we are coming from an interactive form
$fields['password'] = md5($fields['password']);
// else if a regular profile update
} else {
// nick_name is required
if (!isset($fields['nick_name']) || !trim($fields['nick_name'])) {
Logger::error(i18n::s('Please indicate a nick name.'));
return FALSE;
}
// some weird users put spaces around
$fields['nick_name'] = trim($fields['nick_name']);
// nick_name may be already used
if (($used = Users::get($fields['nick_name'])) && $used['id'] != $fields['id']) {
Logger::error(i18n::s('Another member already has this nick name. Please select a different one.'));
return FALSE;
}
// ensure we have a full name
if (!isset($fields['full_name']) || !trim($fields['full_name'])) {
$fields['full_name'] = $fields['nick_name'];
}
// protect from hackers
if (isset($fields['avatar_url'])) {
$fields['avatar_url'] = encode_link($fields['avatar_url']);
}
// set default values
if (!isset($fields['active']) || !$fields['active']) {
$fields['active'] = 'Y';
}
if (isset($fields['selected_editor'])) {
$fields['editor'] = $fields['selected_editor'];
} elseif (isset($context['users_default_editor'])) {
$fields['editor'] = $context['users_default_editor'];
} else {
$fields['editor'] = 'yacs';
}
if (!isset($fields['interface']) || $fields['interface'] != 'C') {
$fields['interface'] = 'I';
}
if (!isset($fields['with_newsletters']) || $fields['with_newsletters'] != 'Y') {
$fields['with_newsletters'] = 'N';
}
if (!isset($fields['without_alerts']) || $fields['without_alerts'] != 'N') {
$fields['without_alerts'] = 'Y';
}
if (!isset($fields['without_confirmations']) || $fields['without_confirmations'] != 'N') {
$fields['without_confirmations'] = 'Y';
}
if (!isset($fields['without_messages']) || $fields['without_messages'] != 'N') {
$fields['without_messages'] = 'Y';
}
if (!isset($fields['birth_date']) || !$fields['birth_date']) {
$fields['birth_date'] = NULL_DATE;
}
// clean provided tags
if (isset($fields['tags'])) {
$fields['tags'] = trim($fields['tags'], " \t.:,!?");
}
// save new settings in session and in cookie
if (Surfer::is($fields['id'])) {
// change preferred editor
$_SESSION['surfer_editor'] = $fields['editor'];
Safe::setcookie('surfer_editor', $fields['editor'], NULL, '/');
// change preferred language
if (isset($fields['language']) && $_SESSION['surfer_language'] != $fields['language']) {
$_SESSION['surfer_language'] = $fields['language'];
$_SESSION['l10n_modules'] = array();
}
}
//.........这里部分代码省略.........