Question: I have a variable named '**`$uname`**' in a function from controller and I need to print the '`$uname`' value in the '`login_form_success`' under view. 

**login.php**

```
public function uname_exist($uname) {
        $this->db->where('username', $uname);
        $query = $this->db->get('login');
        if (!$query->num_rows() > 0) {
            $this->form_validation->set_message(__FUNCTION__, 'Invalid Username');
            return FALSE;
        } else {

            return TRUE;
        }
    }

```

login\_form\_success.php

```
<div class="alert alert-success">Welcome <?php echo $uname; ?> Signed in !</div>

```

Answer: 
You can save the value in **\_SESSION** array as 

```
session_start();
$_SESSION['uname'] = $uname;

```

and use the same value anywhere by using 
`$_SESSION['uname']`
This is only for future visitors:

As you accepted the `SESSION` suggestion, i suggest you to use [CI Session Library](https://www.codeigniter.com/user_guide/libraries/sessions.html) to follow framework standards:

You need to load session library in `autoload.php` as:

```
$autoload['libraries'] = array('session');

```

now you can access the session library in any where in your project just because of `autoload.php` file, this will load session library automatically, now you can store session variables in your controller as:

```
$sessionArray = array('uname'=>$uname);
$this->session->set_userdata($sessionArray);

```

then, this session value should be accessible in your view file as like:

```
echo $this->session->userdata('uname'); // will print your name

```

You can also load your session library inside your controller file, if you are not interested to load in `autoload.php` as:

```
$this->load->library('session'); // but this will not accessible in other controllers.

```