How to get the values using session in codeigniter? - codeigniter

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

Related

Access codeigniter session on unity 3d

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.

User Is Logged Out When Generating PDF with DomPDF & Joomla 2.5

I have integrated DomPDF with a Joomla site that I am working on. I followed the Creating PDF Views article to achieve this and generating PDFs works well except that when the link is clicked and the PDF is generated from the component the user is logged out. I am using Joomla 2.5 & DomPDF 0.6.0 beta 3, the content for the PDF is generated from a custom component but right now it is just flat HTML and follows the instructions in the article for generating the view. I have looked at the code but can't seem to see where the problem is. Any help is greatly appreciated.
EDIT: The user does not get logged out if 'Remember Me' is checked on login. Also didn't mention that I am using Database as the setting for sessions.
Check the custom component that clearing the user object or not.
Any where session_destroy() or unset($user) or any other Factory call to reset the user object.If you can't find such a statement then the make sure the problem with that PDF creation.
In no way you can't get solution then try this.
Before creating PDF section current logged user object id set to Cookie you mentioned that it was not clearing remember me option.
$user = &JFactory::getUser();
echo $user->id //current logged user id.
and the process PDF again put it back to user object like.
$user = &JFactory::getUser($user_id);//from cookie.
This is not a perfect fix but your problem will solve.
Hope this will help..

Codeigniter Session Outside the application folder

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'];
?>

Access cakephp session (auth) from outside cakephp

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.

Joomla Standalone Script in PHP - Handshake

I want to grab the User Object in Joomla in another PHP script.
Anway, what I want to do is grab the Joomla User (JUser) on a non-Joomla page. More or less I want a way to grab the joomla username, email and name etc and throw it to a php script for use in another custom application.
What is the best way to do this? Make a specialized joomla page by importing the framework, grabbing the necessary info from the user, setting those as session variables and then redirecting to the PHP page I want to use that information in?
Or do I just make some sort of link on a Joomla page with querystring variables corresponding to the current User and when they click the link I grab the info from the Querystring?
I'm looking for a best case scenario of how to get the User info to a custom application.
Any insight would be appreciated.
Best way would be to create a User plugin that logs into your script when someone logs into Joomla: Joomla unified logins for forum and a custom made php sub-site
depends on what you want the data for.
the juser data is serialised and stored in the session, so you could reverse engineer that and pull out the juser data... That would be messy.
alternatively you could make a plugin that stores the juser data in a session variable of your own making. the session variable will be available to other php scripts.. asuming they use the same session methods. (joomla has its own)
you could make a plugin that stores the data in a database that is assessible to the other script, or a flat file etc. in essence a similar process to using a session
You could also load up enough of joomla to use the joomla functions that you need to retrieve the juser values.. (messy)

Resources