I have a website made with codeigniter but one of the php document its generated by unity to execute a web application ,the problem is that I have to access to a session data from codeigniter $this->session->set_userdata('logged_in);
but I can't access yo this data from the unity webplayer
I guess you are using CodeIgniter (CI) 2?
In CI 2 you cannot access the session through the superglobal $_SESSION. If you need to use the CI session library than you could do it by enabling session loggin in the database. Then from your unity application you can query the CI session table.
Otherwise you can use a native session library for CI 2, like this one: https://github.com/bcit-ci/CodeIgniter/wiki/Native-session. With a native session library you can access session data through the superglobal $_SESSION.
In CI 3 the session library has been rewritten and uses the superglobal $_SESSION again. So no need to use a third party native session library there.
please print $_SESSION to get all session variable and seeing your code, to access logged_in variable, please use it following.
$logged_in=$this->session->userdata('logged_in);
now $logged_in variable contain logged_in information, please check.
Related
I create a website using codeigniter with registration and login page with session the both are working fine but i need to save the datas in particular user using session and i need to get the values for the particular user in codeigniter. I am newer in codeigniter i dont know how to use the session value to get the particular user value and save the datas in particulate user.
I checked in google no tutorial is help for me can any one help me thanks in advance.
First you have to load session library.Using
$this->load->library('session');
OR in application/config/autoload.php using
$autoload['libraries'] = array('session');
Then you can set session item using
$this->session->set_userdata('name');
And get session item using
$this->session->userdata('name');
For more see docs Codeigniter Session Library
I use view caching in my cakephp based cms with generates the cached views for frontend usage.
The frontend checks whether a user is logged or not to show edit options. It works without the view caching enabled, but when enabled it loses the session.
I've put the session code in no cache tags (index.ctp), but there's no session available
<!--nocache-->
$_SESSION['Auth']['User']['username'];
<!--/nocache-->
How can keep the login session when using view caching?
The anwser is to use the cakephp session helper instead of the native php $_SESSION variable
<!--nocache-->
$this->session->read('Auth.user.name');
<!--/nocache-->
Is it possible to get session outside codeigniter application folder?
It is possible, but not without some work. You can see the details of someone else's problem and their solution in the CodeIgniter forum.
Basically you need take the cookie that CodeIgniter uses to handle it's sessions and unserialize it:
$sess = unserialize($_COOKIE['ci_session']);
You may need to also change settings in your application so that cookies are set for the entire domain, not just for the folder that CodeIgniter sits in.
Its a trick but do work. Place this little naughty code just before login redirect. And now you can use ci_session with php native session too ,have fun !
<?php
session_start();
echo $_SESSION['ci_session'] = $this->session->userdata['ci_session'];
?>
i am newbie here in codeigniter. i was asked to build a-dooid-like-site or a-aboutme-like-site for my local college so they can make their own identity card. i plan building this website using codeigniter since i heard codeigniter is the most easy to understand and i dont have more than 2 weeks to complete the task.
my questions is :
if the dooid build up with codeigniter, how could i make a function
that allows people choosing their direct url. i mean, if i have a
class "User" and there is a "show" method that need
"username" as a parameter. the URL should seems like this one:
www.Mysite.com/User/show/<username>
how could they make a their own url like this one:
www.Mysite.com/<username>
i plan to restrict some "method" guest and it will
be enabled when user login into site. i mean if i have a class
"user" there is a "edit_profiles" method. guest can see the
"show" method but logged in users will be able to
"edit_profiles" after login. on the same class.
can you tell me how the codeigniter session library class concept? i confused with native session php. is there anybody that can show me some links contains session class tutorial that stores session into databases?
Yes this is possible, look into the documentation for custom routes:
http://codeigniter.com/user_guide/general/routing.html
For access control it is simplest to use a prebuilt login library
such as ionauth or tankauth both or which provide the
features you'll require.
The sessions used by CI do not use PHP native sessions. The best guide is in the dosumentation: http://codeigniter.com/user_guide/libraries/sessions.html Where the data is stored is determined by the sessions in the config file and is described in the documentation.
I have a CakePHP website with its own login system using the Auth component. I would like to know if the following is possible:
A user has logged in and is navigating the website. At one point, he can click a link that opens an external php file. With external I mean that it could be in another folder of the same server, but outside the CakePHP app folders.
The "tricky" thing (for me) is to only show the contents of that php file if the user is logged in (to prevent someone without an account accessing those contents). I can't use Auth there because I'm "outside" Cake... I don't know if maybe using $_SESSION, but I don't know how...
Is this even possible? And yes, the php has to be outside the CakePHP app folder system.
Any ideas?
I'll add you also need to set session name to "CAKEPHP" using
session_name('CAKEPHP')
just before your external app session_start() otherwise you could not apply Kashif Khan suggested solution :)
Cheers,
Yes you can access the cakephp SESSION outside cakephp folder. try this session variable
$_SESSION['Auth']
if it exists then check for user here
$_SESSION['Auth']['User']
This is not working in Cakephp3. After calling
session_name("CAKEPHP");
session_start();
Application session is expiring.