# Passing a variable between two actions using Session Component in CakePHP 2.5.3

**URL:** <https://discourse.cakephp.org/t/passing-a-variable-between-two-actions-using-session-component-in-cakephp-2-5-3/2194>\
**Category:** Need Help\
**Created:** [March 5, 2017, 10:22pm UTC](https://discourse.cakephp.org/t/passing-a-variable-between-two-actions-using-session-component-in-cakephp-2-5-3/2194 "2017-03-05T22:22:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarek](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tarek](https://discourse.cakephp.org/u/Tarek)\
**Post date:** [March 5, 2017, 10:22pm UTC](https://discourse.cakephp.org/t/passing-a-variable-between-two-actions-using-session-component-in-cakephp-2-5-3/2194/1 "2017-03-05T22:22:16Z")

</div>

I want to pass a variable between two actions using Session component. the variable session read returns a value in the payment action but it returns NULL in the action checkout.

Here is the code:

```
       //AppController.php
        class AppController extends Controller
        {
            public $components = array('Session', 'Auth', 'Cookie', 'Email');
            // rest of the code    
        }
        //OrderController.php
        class OrdersController extends AppController
        {
            public $components = array('Paginator','Session'); 
            // rest of the code
            public function payment($hash=null)
            {
                //some code
                $priceTND = 123,55; //just for the test  
                $this->Session->write('priceCTP',$priceTND); 
                //var_dump($this->Session->read('priceCTP')); it returns 123.55
                // rest of the code
            }
            public function checkout()
            { 
                $this->render("checkout",FALSE);

                $price = $this->Session->read('priceCTP');
                var_dump($price); // it returns NULL
                // rest of the code
            }
        }
```

---

<div class="post-metadata">

**Author:** ![rogerpro](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rogerpro/32/466_2.png) [@rogerpro](https://discourse.cakephp.org/u/rogerpro)\
**Post date:** [March 7, 2017, 12:23am UTC](https://discourse.cakephp.org/t/passing-a-variable-between-two-actions-using-session-component-in-cakephp-2-5-3/2194/2 "2017-03-07T00:23:49Z")

</div>

Hi Tarek,

Your app is using CakePHP 2.5.3, which was released on July 2014. As a first approach to the issue, I would update to 2.9.6, last release of CakePHP 2 so far. Or, at least, to 2.5.9, which was the last security update of the 2.5 branch.

Specifically, versions 2.5.4 and 2.5.6 solved some session issues:

> **[CakePHP - Build fast, grow solid | Changelogs](https://cakephp.org/changelogs)**
>
> CakePHP Changelogs.

  

> **[CakePHP - Build fast, grow solid | Changelogs](https://cakephp.org/changelogs)**
>
> CakePHP Changelogs.

---

<div class="post-metadata">

**Author:** ![Tarek](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tarek](https://discourse.cakephp.org/u/Tarek)\
**Post date:** [March 7, 2017, 10:22am UTC](https://discourse.cakephp.org/t/passing-a-variable-between-two-actions-using-session-component-in-cakephp-2-5-3/2194/3 "2017-03-07T10:22:27Z")

</div>

Thank you man, you are right. I have to upgrade the code.
