পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Wednesday, March 8, 2017

Phalcon - Session Management

Sessions are server-side information storage which helps in user interaction with the website or web application. Each session is uniquely defined with a session ID, which is passed to the web server whenever the browser makes an HTTP request. The session ID is paired every time with the internal database such that all stored variables are retrieved.

Sessions in Phalcon

Phalcon uses session components which includes the wrappers to access the session data.
Following are the features in Phalcon −
  • Session data can be isolated from other components on the same domain.
  • According to the application needs, the session value can be changed with the help of the session adapter.

Starting a Session in Phalcon

All the session activities are associated with the adapter files which are declared in Services.php file inside the /config folder of the web application.
/** 
   * Start the session the first time some component requests the session service 
*/ 
$di->setShared('session', function () { 
   $session = new SessionAdapter(); 
   $session->start();  
   return $session; 
});

Creating a Session

Step 1 − Create a session controller for instantiating a session such that data can be retrieved appropriately.
Command Prompt Step 2 − Create a session with a name and value.
<?php  

class SessionController extends \Phalcon\Mvc\Controller { 
   public function indexAction() { 
      //Define a session variable 
      $this->session->set("user-name", "Omkar"); 
      
      //Check if the variable is defined 
      if ($this->session->has("user-name")) { 
         //Retrieve its value 
         $name = $this->session->get("user-name"); 
         echo($name); 
      } 
   } 
} 
The above code produces the following output.
Code

Removing a Session

It is possible to destroy the session or unset some variable values within the session in Phalcon.
Following is the syntax to unset variable values in session.
$this->session->remove(<variable-name>); 
As shown in the example above, the variable name created in the session is “data-content” which can be removed using the following code.
public function removeAction() { 
   // Remove a session variable with associated session 
   $this->session->remove("data-content"); 
}
; Following is the syntax to destroy the complete session.
$this->session->destroy(); 

No comments:

Post a Comment