Table of Contents
yii操作session实例简介,yiisession实例
yii 设置session时间怎设置 ? 在mainphp中设置,还是在页面内也可以设置help3ks
yii怎配置SESSION
Home php教程 php手册 yii操作session实例简介,yiisession实例

yii操作session实例简介,yiisession实例

Jun 13, 2016 am 09:27 AM
session yii

yii操作session实例简介,yiisession实例

本文简述了Yii框架中使用session的方法,具体步骤如下:

一、与标准php代码的区别:

在Yii框架中,你不需要像标准PHP代码那样使用session_start(),
在Yii框架中,autoStart 属性缺省被设置为true,所以,
虽然没有使用session_start(),你仍然可以使用$_SESSION全局变量,但最好使用Yii框架封装的Yii::app->session

二、session变量的使用:

设置session:

Yii::app()->session['var']='value';
Copy after login

使用session:

echo Yii::app()->session['var'];
Copy after login

移除session:

unset(Yii::app()->session['var']);
Copy after login

更为复杂一点的使用时如何配置你的session
配置项可设在 protected/config/main.php的components中:

'session'=>array(
  'autoStart'=>false(/true),
  'sessionName'=>'Site Access',
  'cookieMode'=>'only',
  'savePath'='/path/to/new/directory',
),

Copy after login

将session保持在数据库的设置:

'session' => array (
  'class' => 'system.web.CDbHttpSession',
  'connectionID' => 'db',
  'sessionTableName' => 'actual_table_name',
),

Copy after login

此外,为了调试,有时需要知道当前用户的session ID,
该值就在:

Yii::app()->session->sessionID
Copy after login

最后,当用户退出登录(logout),你需要消除痕迹,可使用:

Yii::app()->session->clear() 
Copy after login

移去所有session变量,然后,调用

Yii::app()->session->destroy() 
Copy after login

移去存储在服务器端的session数据。

yii 设置session时间怎设置 ? 在mainphp中设置,还是在页面内也可以设置help3ks

你首先要在main.php中设置session timeout,'sessionTimeoutSeconds'=>300,然后在yii::app()->user->setState('userSessionTimeout',time()+Yii::app()->params['sessionTimeoutSeconds']);页面进行调用。
希望可以帮到你
 

yii怎配置SESSION

session不是直接使用就可以了吗?
 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve session failure How to solve session failure Oct 18, 2023 pm 05:19 PM

Session failure is usually caused by the session lifetime expiration or server shutdown. The solutions: 1. Extend the lifetime of the session; 2. Use persistent storage; 3. Use cookies; 4. Update the session asynchronously; 5. Use session management middleware.

Solution to PHP Session cross-domain problem Solution to PHP Session cross-domain problem Oct 12, 2023 pm 03:00 PM

Solution to the cross-domain problem of PHPSession In the development of front-end and back-end separation, cross-domain requests have become the norm. When dealing with cross-domain issues, we usually involve the use and management of sessions. However, due to browser origin policy restrictions, sessions cannot be shared by default across domains. In order to solve this problem, we need to use some techniques and methods to achieve cross-domain sharing of sessions. 1. The most common use of cookies to share sessions across domains

How to solve the problem that the Springboot2 session timeout setting is invalid How to solve the problem that the Springboot2 session timeout setting is invalid May 22, 2023 pm 01:49 PM

Problem: Today, we encountered a setting timeout problem in our project, and changes to SpringBoot2’s application.properties never took effect. Solution: The server.* properties are used to control the embedded container used by SpringBoot. SpringBoot will create an instance of the servlet container using one of the ServletWebServerFactory instances. These classes use server.* properties to configure the controlled servlet container (tomcat, jetty, etc.). When the application is deployed as a war file to a Tomcat instance, the server.* properties do not apply. They do not apply,

How to implement SMS login in Redis shared session application How to implement SMS login in Redis shared session application Jun 03, 2023 pm 03:11 PM

1. Implementing SMS login based on session 1.1 SMS login flow chart 1.2 Implementing sending SMS verification code Front-end request description: Description of request method POST request path /user/code request parameter phone (phone number) return value No back-end interface implementation: @Slf4j@ ServicepublicclassUserServiceImplextendsServiceImplimplementsIUserService{@OverridepublicResultsendCode(Stringphone,HttpSessionsession){//1. Verify mobile phone number if

What are the differences between JavaScript and PHP cookies? What are the differences between JavaScript and PHP cookies? Sep 02, 2023 pm 12:29 PM

JavaScriptCookies Using JavaScript cookies is the most effective way to remember and track preferences, purchases, commissions and other information. Information needed for a better visitor experience or website statistics. PHPCookieCookies are text files that are stored on client computers and retained for tracking purposes. PHP transparently supports HTTP cookies. How do JavaScript cookies work? Your server sends some data to your visitor's browser in the form of a cookie. Browsers can accept cookies. If present, it will be stored on the visitor's hard drive as a plain text record. Now, when a visitor reaches another page on the site

How PHP handles session issues in WeChat mini programs How PHP handles session issues in WeChat mini programs Jun 02, 2023 pm 03:40 PM

In recent years, WeChat mini programs have become popular all over the world and have become the platform of choice for many enterprises and individual developers. In the development of mini programs, we often encounter session problems, that is, how to save user login status in mini programs. This problem is not unfamiliar to website developers, but it is a little different in small programs. This article will introduce how to use PHP to solve session problems in WeChat mini programs. 1. Overview of the mini program login process The login process of the mini program is similar to the login process of the website and is divided into the following steps:

How to use PHP framework Yii to develop a highly available cloud backup system How to use PHP framework Yii to develop a highly available cloud backup system Jun 27, 2023 am 09:04 AM

With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

How to modify the Session configuration in ThinkPHP6 How to modify the Session configuration in ThinkPHP6 Jun 03, 2023 pm 06:58 PM

1. Introduction to Session In Web applications, Session is a data structure saved on the Web server and used to store user information. When a user visits a website, the server creates a Session and sends the Session ID to the client browser. When the browser returns a request, it will bring the ID of the Session. The server can find the user's Session through the ID and read or modify the user's information from the Session. The role of Session can be summarized into the following aspects: storing user information. For example, the user's login status, shopping cart contents, form data, etc. Achieve cross-page data sharing

See all articles