Welcome Guest, Not a member yet? Register   Sign In
pulling CI into another system
#1

[eluser]phazei[/eluser]
I recall an answer to this being mentioned in another post for a different issue, but I couldn't find it anywhere.

I have a system that I'm plugging in to CI that needs to make sure the user is logged in. All I need to do is check the sessions, but since CI doesn't use standard sessions, I need to be able to check $this->session->userdata.

So what do I include to be able to use the CI data for the validation?
#2

[eluser]gtech[/eluser]
I recommend to read the

Adding Custom Session Data in the [url="http://ellislab.com/codeigniter/user-guide/libraries/sessions.html"]sessions section of the userguide[/url]

Once you understand the guide you can add your own is_admin variable to the session,
so if the user logs in as an admin user you can set your is_admin variable to TRUE in the session.

you can check the variable when trying to access admin pages.



I would also read about Saving Session Data to a Database in the session guide for added security. once configured to use the database you shouldn't have to do anything extra.
#3

[eluser]phazei[/eluser]
I've read that.

I'm already saving all session data to a database.

But if I'm using a page that's not part of codeigniter, it can't access CodeIgniters sessions. That's the problem. I have another system, totally separate from codeigniter.

All I need to know is how to pull the CI Super object into a file that's not part of CI.

I can't use:
$ci =& get_instance();
because I'm not within the framework.
#4

[eluser]gtech[/eluser]
ok I understand the problem.. somthing I haven't tried before..

I believe $_SESSION is still available in CI (the php session variable).. there is also somthing called native session [url="http://codeigniter.com/wiki/Native_session/"](see link)[/url] which allows you to use a similar interface to the CI session.

I don't know if this will help you. this of course is assuming your other application is using php.
#5

[eluser]Colin Williams[/eluser]
CI still uses the $_SESSION super global, but it may store values in the database. If this is the case, your non-CI app will have to get a hold of the session id (either in $_COOKIE or $_SESSION) and query the db for the data.
#6

[eluser]phazei[/eluser]
CI can use the $_SESSION super global, but it doesn't utilize it.
In the $_COOKIE it stores:
Code:
[ci_session] => a:4:{s:10:\"session_id\";s:32:\"03756b71eb18d0ac038dcd2b75b8baea\";s:10:\"ip_address\";s:13:\"68.2xx.2xx.2xx\";s:10:\"user_agent\";s:50:\"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv\";s:13:\"last_activity\";s:10:\"1245123099\";}95f84d6a3be927745b9eda88d7562d8e

I could then do a db query to the session id. But then I'd need lots of extra code to parse that string. It's not anything standard that I know. The s:## seems to be the length. And then I'd also have to load the db. I believe I've seen a simple include that would pull all the code in that was needed. And if I use CI's encrypted sessions, I'd need to copy all that code for decryption and have a copy of the key. There's nothing easy going in that direction.


Specifically what I'm doing is integrating TinyMCE. Usually that doesn't require authentication, but I'm using this 3rd party file manager inside of it that uses TinyMCE's plug-in architecture. It has a section for authentication. I actually found a solution where I can just direct it to a ci that's part of CI, have that page set some $_SESSION vars just for it, and then have it forward to the page after settings up the vars.

But none-the-less, I would still like to know what I was attempting since it could be of use. I thought I recalled someone mentioning how in an old thread of mine that was asking about some AJAX pages that were independent of CI, but I can't seem to find it.

I think it might something as simple as including some CI php file at the top of the file, but I don't know.
#7

[eluser]Colin Williams[/eluser]
unserialize()

http://www.php.net/serialize
http://www.php.net/unserialize
#8

[eluser]phazei[/eluser]
nifty Smile
#9

[eluser]phazei[/eluser]
It seems what I was attempting to work around it won't work. The app does a header redirect to the auth page with the return url as a get variable on the string, which won't work with my CI install. Something like /controller/model/?return_url=encoded url
CI just gives 404. I can't post the data.

So if this external app could somehow include what's needed to access the CI super global, that would be great...

Anyone know?
#10

[eluser]Colin Williams[/eluser]
[quote author="phazei" date="1245317576"]It seems what I was attempting to work around it won't work. The app does a header redirect to the auth page with the return url as a get variable on the string, which won't work with my CI install. Something like /controller/model/?return_url=encoded url
CI just gives 404. I can't post the data.

So if this external app could somehow include what's needed to access the CI super global, that would be great...

Anyone know?[/quote]

The front controller, index.php. Still, this is a bad route to go.




Theme © iAndrew 2016 - Forum software by © MyBB