Welcome Guest, Not a member yet? Register   Sign In
getting access to CI session in external plugin
#1

[eluser]bill19[/eluser]
Hi everyone,

I am working with the blueimp jquery fileupload plugin as a standalone resource within my CI project. At one point the plugin refers to its own index.php file, and I would like to have access to the CI session variable within this file. Unfortunately $this->session->userdata is not available in this context. What can I do to gain access to the session info, in this non library setting.

Thanks,

Bill
#2

[eluser]john_j[/eluser]
Will an ajax call to CI (so that it returns the session variable) work?
#3

[eluser]DarkManX[/eluser]
Let your session use the database. Then you can take sessionvars you need directly from the db. If you dont want to use db for session just take the data you need directly from the cookie - you may have to decode the cookie before.
#4

[eluser]bill19[/eluser]
Hi guys,

Thanks for the replies!

John_j. I'm not very knowledgeable with ajax. Can you post a link or reference with more details? I'd be interested in investigating further.

DarkManX, I would love to take the session data directly from the cookie but the question is how to this. Codeigniter's $this is not recognized in this external plugin, so I can't get $this->session->userdata to work. Although it is in php, it is in an asset folder as opposed to your standard controller or library. I don't think $ci =& get_instance() would work in this context would it?

Bill

#5

[eluser]DarkManX[/eluser]
http://de3.php.net/manual/en/reserved.va...ookies.php
#6

[eluser]bill19[/eluser]
Hi everyone,

I came across http://ellislab.com/forums/viewthread/144512/

This worked for me:

Code:
$cookie = $_COOKIE['ci_session'];
$cookie = unserialize($cookie);
$session_id = $cookie['session_id'];

Regards,

Bill
#7

[eluser]DarkManX[/eluser]
Well, as i told $_COOKIE...
If your uploading section requires permissions for users you will need to encode & decode your cookie data because of xss.
#8

[eluser]bill19[/eluser]
Thank you,

your $_cookie reference was a light switch going on for me. On cookie encoding, can you recommend an approach in codeigniter.

Regards,

Bill
#9

[eluser]DarkManX[/eluser]
Well, i never looked up how ci encode cookies but you can do:
system/Session.php

If you are not able to reconstruct it in your own function just copy
everything from the library and replace the vars.
#10

[eluser]bill19[/eluser]
Thank you




Theme © iAndrew 2016 - Forum software by © MyBB