本文整理汇总了PHP中Session::clear方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::clear方法的具体用法?PHP Session::clear怎么用?PHP Session::clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveNewsArticle
function saveNewsArticle($data, Form $form)
{
try {
$form->clearMessage();
$form->resetValidation();
if ($data['newsID']) {
$this->manager->updateNews($data);
} else {
$this->manager->postNews($data);
}
Session::clear("FormInfo.Form_NewsRequestForm.data");
return Controller::curr()->redirect('/news-add/?saved=1');
} catch (EntityValidationException $ex1) {
$messages = $ex1->getMessages();
$msg = $messages[0];
$form->addErrorMessage('Headline', $msg['message'], 'bad');
SS_Log::log($msg['message'], SS_Log::ERR);
// Load errors into session and post back
Session::set("FormInfo.Form_NewsRequestForm.data", $data);
return $this->redirectBack();
} catch (Exception $ex) {
$form->addErrorMessage('Headline', 'Server Error', 'bad');
SS_Log::log($ex->getMessage(), SS_Log::ERR);
// Load errors into session and post back
Session::set("FormInfo.Form_NewsRequestForm.data", $data);
return $this->redirectBack();
}
}
示例2: doContactFormSubmit
/**
* Handles the submission of the contact form. Checks spam and builds and sends the email
*
* @param array The form data
* @param Form The Form object
*/
public function doContactFormSubmit($data, $form)
{
Session::set("FormData.{$form->FormName()}", $data);
$proxy = $form->proxy;
foreach ($proxy->getSpamProtection() as $spam) {
if ($spam->isSpam($data, $form)) {
$form->sessionMessage($spam->getMessage(), "bad");
$spam->logSpamAttempt($this->owner->request);
return $this->owner->redirectBack();
}
}
if ($func = $proxy->getOnBeforeSend()) {
$result = $func($data, $form, $proxy);
if ($result === false) {
return $this->owner->redirectBack();
}
}
$this->sendEmail($data, $form);
Session::clear("FormData.{$form->FormName()}");
if ($func = $proxy->getOnAfterSend()) {
$func($data, $form, $proxy);
}
if ($proxy->getSuccessURL()) {
return $this->owner->redirect($proxy->getSuccessURL());
} else {
if (Director::is_ajax()) {
return new SS_HTTPResponse($proxy->getSuccessMessage());
}
$form->sessionMessage(strip_tags($proxy->getSuccessMessage()), 'good');
return $this->owner->redirectBack();
}
}
示例3: submit
function submit($data, $form)
{
// if rewards added and get it button clicked then validate and save to order object
if (isset($data['action_submit']) && isset($data['Quantity'])) {
Session::clear($this->controller->RewardsSessionKey());
foreach ($data['Quantity'] as $ProductID => $quantity) {
$item = $this->controller->newReward($ProductID, $quantity);
Session::set($this->controller->RewardsSessionKey($ProductID), serialize($item));
}
if ($this->controller->RewardsTotalPoints() > Page_Controller::MemberPointsBalance()) {
$this->sessionMessage('You do not have enough points to purchase these rewards.', 'error');
Director::redirectBack();
return;
}
$new_items = $this->controller->RewardItems();
}
//delete all existing reward items for this order
$order_items = $this->controller->Order()->RewardItems();
foreach ($order_items as $o_item) {
$o_item->delete();
}
// then flush rewards from session
Session::clear($this->controller->RewardsSessionKey());
//then link the reward items to the order
if (isset($new_items)) {
foreach ($new_items as $item) {
$item->write();
}
}
// then redirect to next step
Director::redirect($this->controller->Link() . 'checkoutstep/orderconfirmationandpayment/');
}
示例4: dologin
/**
* Login form handler method
*
* This method is called when the user clicks on "Log in"
*
* @param array $data Submitted data
*/
public function dologin($data)
{
if ($this->performLogin($data)) {
Session::clear('SessionForms.MemberLoginForm.Email');
Session::clear('SessionForms.MemberLoginForm.Remember');
if (isset($_REQUEST['BackURL']) && ($backURL = $_REQUEST['BackURL'])) {
Session::clear("BackURL");
Director::redirect($backURL);
} else {
Director::redirectBack();
}
} else {
Session::set('SessionForms.MemberLoginForm.Email', $data['Email']);
Session::set('SessionForms.MemberLoginForm.Remember', isset($data['Remember']));
if (isset($_REQUEST['BackURL']) && ($backURL = $_REQUEST['BackURL'])) {
Session::set('BackURL', $backURL);
}
if ($badLoginURL = Session::get("BadLoginURL")) {
Director::redirect($badLoginURL);
} else {
// Show the right tab on failed login
Director::redirect(Director::absoluteURL(Security::Link("login")) . '#' . $this->FormName() . '_tab');
}
}
}
示例5: getCaptcha
function getCaptcha()
{
$key = TextCaptchaField::config()->ApiKey;
$url = 'http://api.textcaptcha.com/' . $key;
//if(Session::get('setCaptcha') == true && Session::get('question') === null && Session::get('captchaFail') != true) {}
try {
$xml = @new SimpleXMLElement($url, null, true);
} catch (Exception $e) {
// if there is a problem, use static fallback..
$fallback = '<captcha>' . '<question>Is ice hot or cold?</question>' . '<answer>' . md5('cold') . '</answer></captcha>';
$xml = new SimpleXMLElement($fallback);
}
// display question as part of form
$question = (string) $xml->question;
// store answers in session
$ans = array();
foreach ($xml->answer as $hash) {
$ans[] = (string) $hash;
}
Session::set('captcha', $ans);
Session::set('question', $question);
Session::set('setCaptcha', true);
Session::clear('captchaFail');
return true;
}
示例6: doChangePassword
/**
* @param array $data
* @return SS_HTTPResponse|void
*/
function doChangePassword(array $data)
{
try {
$token = Session::get('AutoLoginHash');
$member = $this->password_manager->changePassword($token, @$data['NewPassword1'], @$data['NewPassword2']);
Session::clear('AutoLoginHash');
$back_url = isset($_REQUEST['BackURL']) ? $_REQUEST['BackURL'] : '/';
return OpenStackIdCommon::loginMember($member, $back_url);
} catch (InvalidResetPasswordTokenException $ex1) {
Session::clear('AutoLoginHash');
Controller::curr()->redirect('login');
} catch (EmptyPasswordException $ex2) {
$this->clearMessage();
$this->sessionMessage(_t('Member.EMPTYNEWPASSWORD', "The new password can't be empty, please try again"), "bad");
Controller::curr()->redirectBack();
} catch (PasswordMismatchException $ex3) {
$this->clearMessage();
$this->sessionMessage(_t('Member.ERRORNEWPASSWORD', "You have entered your new password differently, try again"), "bad");
Controller::curr()->redirectBack();
} catch (InvalidPasswordException $ex4) {
$this->clearMessage();
$this->sessionMessage(sprintf(_t('Member.INVALIDNEWPASSWORD', "We couldn't accept that password: %s"), nl2br("\n" . $ex4->getMessage())), "bad");
Controller::curr()->redirectBack();
}
}
示例7: authenticate
/**
* Performs the login, but will also create and sync the Member record on-the-fly, if not found.
*
* @param array $data
* @param Form $form
* @return bool|Member|void
* @throws SS_HTTPResponse_Exception
*/
public static function authenticate($data, Form $form = null)
{
$service = Injector::inst()->get('LDAPService');
$result = $service->authenticate($data['Username'], $data['Password']);
$success = $result['success'] === true;
if (!$success) {
if ($form) {
$form->sessionMessage($result['message'], 'bad');
}
return;
}
$data = $service->getUserByUsername($result['identity']);
if (!$data) {
if ($form) {
$form->sessionMessage(_t('LDAPAuthenticator.PROBLEMFINDINGDATA', 'There was a problem retrieving your user data'), 'bad');
}
return;
}
// LDAPMemberExtension::memberLoggedIn() will update any other AD attributes mapped to Member fields
$member = Member::get()->filter('GUID', $data['objectguid'])->limit(1)->first();
if (!($member && $member->exists())) {
$member = new Member();
$member->GUID = $data['objectguid'];
$member->write();
}
Session::clear('BackURL');
return $member;
}
示例8: StartSurvey
function StartSurvey($data, $form)
{
try {
$data = SQLDataCleaner::clean($data);
$data['MembershipType'] = 'community';
Session::set("FormInfo.{$form->FormName()}.data", $data);
$profile_page = EditProfilePage::get()->first();
$member = $this->member_manager->registerMobile($data, new MemberRegistrationSenderService());
//Get profile page
if (!is_null($profile_page)) {
//Redirect to profile page with success message
Session::clear("FormInfo.{$form->FormName()}.data");
$request = Controller::curr()->getRequest();
$back_url = $request->postVar('BackURL');
$link = $profile_page->Link('?success=1');
if (!empty($back_url)) {
$link .= "&BackURL=" . $back_url;
}
return OpenStackIdCommon::loginMember($member, $link);
}
} catch (EntityValidationException $ex1) {
Form::messageForForm($form->FormName(), $ex1->getMessage(), 'bad');
//Return back to form
SS_Log::log($ex1->getMessage(), SS_Log::WARN);
return Controller::curr()->redirectBack();
} catch (Exception $ex) {
Form::messageForForm($form->FormName(), "There was an error with your request, please contact your admin.", 'bad');
//Return back to form
SS_Log::log($ex->getMessage(), SS_Log::ERR);
return Controller::curr()->redirectBack();
}
}
示例9: doAddItemToCart
public function doAddItemToCart($data)
{
$product = Product::get()->byID($data['ProductID']);
$customisations = array();
foreach ($data as $key => $value) {
if (!(strpos($key, 'customise') === false) && $value) {
$custom_data = explode("_", $key);
if ($custom_item = ProductCustomisation::get()->byID($custom_data[1])) {
$modify_price = 0;
// Check if the current selected option has a price modification
if ($custom_item->Options()->exists()) {
$option = $custom_item->Options()->filter("Title", $value)->first();
$modify_price = $option ? $option->ModifyPrice : 0;
}
$customisations[] = array("Title" => $custom_item->Title, "Value" => $value, "ModifyPrice" => $modify_price);
}
}
}
if ($product) {
$cart = ShoppingCart::create();
$cart->add($product, $data['Quantity'], $customisations);
$cart->save();
// Clear any postage data that has been set
Session::clear("Commerce.PostageID");
$message = _t('Commerce.AddedItemToCart', 'Added item to your shopping cart');
$message .= ' <a href="' . $cart->Link() . '">';
$message .= _t('Commerce.ViewCart', 'View cart');
$message .= '</a>';
$this->controller->setSessionMessage("success", $message);
}
return $this->controller->redirectBack();
}
示例10: onBeforeIndex
function onBeforeIndex($controller)
{
Session::clear("ViewDeploymentSurveyStatistics_survey_range");
Session::clear("ViewDeploymentStatistics_survey_range");
Session::clear("ViewDeploymentsPerRegion_survey_range");
Session::clear("global_survey_range");
}
示例11: onPlaceOrder
public function onPlaceOrder()
{
if (session_id()) {
unset($_SESSION['Cart']);
Session::clear('Cart');
}
}
示例12: saveEventRegistrationRequest
function saveEventRegistrationRequest($data, Form $form)
{
// Check if the honeypot has been filled out
if (@$data['username']) {
SS_Log::log(sprintf('EventRegistrationRequestForm honeypot triggered (data: %s)', http_build_query($data)), SS_Log::NOTICE);
return $this->httpError(403);
}
try {
$this->event_registration_request_manager->registerEventRegistrationRequest($data);
Session::clear("FormInfo.Form_EventRegistrationRequestForm.data");
$form->clearMessage();
return $this->redirect($this->Link('?saved=1'));
} catch (EntityValidationException $ex1) {
$messages = $ex1->getMessages();
$msg = $messages[0];
$form->addErrorMessage('City', $msg['message'], 'bad');
SS_Log::log($msg['message'], SS_Log::ERR);
// Load errors into session and post back
Session::set("FormInfo.Form_EventRegistrationRequestForm.data", $data);
return $this->redirectBack();
} catch (Exception $ex) {
$form->addErrorMessage('Title', 'Server Error', 'bad');
SS_Log::log($ex->getMessage(), SS_Log::ERR);
// Load errors into session and post back
Session::set("FormInfo.Form_EventRegistrationRequestForm.data", $data);
return $this->redirectBack();
}
}
示例13: register
/**
* Handles validation and saving new Member objects, as well as sending out validation emails.
*/
public function register($data, Form $form)
{
if ($member = $this->addMember($form)) {
$this->addRegistration($form, $member);
if (!$this->RequireApproval && $this->EmailType != 'Validation' && !$this->AllowAdding) {
$member->logIn();
}
if ($this->RegistrationRedirect) {
if ($this->PostRegistrationTargetID) {
$this->redirect($this->PostRegistrationTarget()->Link());
return;
}
if ($sessionTarget = Session::get('MemberProfile.REDIRECT')) {
Session::clear('MemberProfile.REDIRECT');
if (Director::is_site_url($sessionTarget)) {
$this->redirect($sessionTarget);
return;
}
}
}
return $this->redirect($this->Link('afterregistration'));
} else {
return $this->redirectBack();
}
}
示例14: index
function index()
{
Session::clear("loggedInAs");
Requirements::themedCSS("form");
// if the email address is given
$emailAddress = Convert::raw2sql($this->urlParams['Email']);
$mailingListID = (int) $this->urlParams['MailingList'];
if ($mailingListID) {
$mailingList = DataObject::get_by_id("NewsletterType", $mailingListID);
}
// try to find the member with the email specified
if ($emailAddress) {
$member = DataObject::get_one('Member', "`Email` = '{$emailAddress}'");
} else {
$member = false;
}
// if the email address and mailing list is given in the URL and both are valid,
// then unsubscribe the user
if ($member && $mailingList && $member->inGroup($mailingList->GroupID)) {
$this->unsubscribeFromList($member, $mailingList);
$url = '/done/' . $member->Email . '/' . $mailingList->Title;
Director::redirect(Director::absoluteBaseURL() . $this->RelativeLink() . $url);
return;
} elseif ($member) {
$listForm = $this->MailingListForm($member);
} else {
$listForm = $this->EmailAddressForm();
}
if ($this->urlParams['Email'] == "done") {
$listForm->sessionMessage(_t('Unsubscribe.SUCCESS', 'Thank you. You have been removed from the selected groups'), "good");
}
return $this->customise(array('Content' => $listForm->forTemplate()))->renderWith('Page');
}
示例15: publish
/**
* When an error page is published, create a static HTML page with its
* content, so the page can be shown even when SilverStripe is not
* functioning correctly before publishing this page normally.
* @param string|int $fromStage Place to copy from. Can be either a stage name or a version number.
* @param string $toStage Place to copy to. Must be a stage name.
* @param boolean $createNewVersion Set this to true to create a new version number. By default, the existing version number will be copied over.
*/
function publish($fromStage, $toStage, $createNewVersion = false)
{
// Temporarily log out when producing this page
$loggedInMember = Member::currentUser();
Session::clear("loggedInAs");
$alc_enc = isset($_COOKIE['alc_enc']) ? $_COOKIE['alc_enc'] : null;
Cookie::set('alc_enc', null);
$oldStage = Versioned::current_stage();
// Run the page
Requirements::clear();
$controller = new ErrorPage_Controller($this);
$errorContent = $controller->run(array())->getBody();
if (!file_exists("../assets")) {
mkdir("../assets", 02775);
}
if ($fh = fopen("../assets/error-{$this->ErrorCode}.html", "w")) {
fwrite($fh, $errorContent);
fclose($fh);
}
// Restore the version we're currently connected to.
Versioned::reading_stage($oldStage);
// Log back in
if ($loggedInMember) {
Session::set("loggedInAs", $loggedInMember->ID);
}
if (isset($alc_enc)) {
Cookie::set('alc_enc', $alc_enc);
}
return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion);
}