title: Undefined global variable in CodeIgniter
body: <p>I want to use a global variable in a CodeIgniter Controller, I tried to use the solution from this post <a href="https://stackoverflow.com/questions/7151990/codeigniter-global-variable-within-controller">Codeigniter global variable within controller</a> but it doesn't work for me. I think because first I call the <code>session</code> function, and after the user's authentication the <code>user</code> function, but the web page has been refreshed and the value is lost. Is there any to store the variable somewhere after the first's function call and retrieve it later from the second function?</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
    class Auth extends CI_Controller
  {
      //Constructor
        function __construct() {
            parent::__construct();
        }
  
      public $user;
  
      public function session()
      {
  
          require 'facebook/facebook.php';
  
      $facebook = new Facebook(array(  
      'appId'  =&gt; '***********',  
      'secret' =&gt; '*****************',  
      'cookie' =&gt; true
      ));  
  
      $user = $facebook-&gt;getUser();
  
        if ($user) {
          $uid = $facebook-&gt;getUser();
  
        } else {
          // proceed knowing you require user login and/or authentication
          $login_url = $facebook-&gt;getLoginUrl();  
            header("Location: ".$login_url);  
        }
      }
  
      public function user()
      {
          echo ($user);
      }
  
  }
  </code></pre>