Codeigniter Session Outside the application folder - codeigniter

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

Related

Laravel 5.3 session cookies are not creating in browser

I am facing token mismatch issue in new server while working fine in localhost. I have tried every possible way to clear cache and give SESSION_DOMAIN path in env but all seems useless.
Also session cookies are not being created in web browser while creating in storage/framework/session folder.
Please help me !
Are you getting tokenMismatchException exception?
If yes, some of the possible reasons are:
Check your files for PHP end tag "?>", if exists remove it. For more detail refer to this link.
You may need to use web middleware. For more detail refer to this link (although it is about laravel 5.2 but, it may work for your situation too).
Another thing to try is checking for web middleware presence. Normally it should be automatically applied to routes/web.php
Route::group(['middleware' => ['web']], function () {
<routes>
});
Also check out https://laravel.com/docs/5.3/upgrade to see if you have any code that might have been influenced by this update.
And lastly, it would be nice if you could post a piece of code which is responsible for sessions in your app.

codeigniter hosting issue session_start(): Cannot send session cookie

enter image description hereI have created a web system using codeigniter. I don't have any errors while testing it in local host. after hosting the website to live host it generates some errors which cannot resolved. The errors is "session_start(): Cannot send session cookie ". I searched regarding this issue and did all possible changes in coding and config file. I have clearly define the session saving location in config. Also when I try to remove all session functionalities in my website, it generate another error which is "base_url() is not a function". Please guide further with solution. thanks all.
In application/config/config.php
$config['sess_save_path'] = sys_get_temp_dir();
Bang!
UPDATE: Regardless base_url() make sure you have the url helper loaded in the autoload.

Securing roxyfilemanager in CodeIgniter

I'm trying to build a website for myself. It has front and back end.
In the back end I have TinyMCE and I installed the standalone roxyfileman file manger and have it working perfect with my codeigniter site, but there's a catch.
I have my back end password protected via codeigniter sessions using a database
(I don't use password protected directories). I see that roxyfileman is accessible directly via browser if a user knows here to look, and a hacker could delete all pictures via file manager.
Example:
sitename/js/fileman/index.html
How can I secure the filemanager with codeigniter or any other way that will forbid direct access to the page?
In my case sessions are saved in database.
I gess I must figure out a way to connect the standalone filemanager to codeigniter and database and validate if a valid user is executing the filemanager.
Please advise on how to achieve this.
Solution for me:
Eventually I managed to find a great contribution from a developer.
Thanks to him I sorted my issue out.
Solution found here:
https://github.com/codinghamster/coreigniter

Codeigniter anchor can't find link

I am using CodeIgniter to design a website, and I am having trouble getting anchor to work correctly.
Here is how I am using it. It is used in a file in views folder of application in codeigniter.
<?php echo anchor('/profile', 'PROFILE'); ?>
My intention is to have anchor load the profile controller, which is in the controllers of application in codeigniter. However, when I clink on the link, it says that the the file is not found.
I autoload the url helper functions alreader, and other functions from that file are working, like site_url() .
I don't know what I could have missed? Do you ave any suggestions? This is my second project with codeigniter, so I am still learning.
EDIT: Yes, I am following the naming convention in codeigniter, and the file has an index function. I tried without the forward slash and it still gives the same result.
The HTML link that this produces is localhost/profile. This is what I Should get right? Since for codeigniter, it's url/controller/function. I did a mod rewrite to remove index.php from the url, but that shouldn't be a problem, should it? I'll try and check the base url again.
Are you sure you need the leading forward slash?
Have you tried:
<?php echo anchor('profile', 'PROFILE'); ?>
You would only be using the slash if you are trying to get into the "profile" sub folder inside your controllers folder.
What helps me when urls get confusing is to type into the browser the full url to the path I want to get to (to make sure I'm not getting a 404, etc). From there you can start from the end and go back to see what you are missing.
But you generally want to start with a controller name and add the function you are calling like:
anchor(controllerName/functionName)
See CodeIgniter URL Helper for examples.
EDIT: also - you may need to check what your config base_url is set to. if there's fancy .htaccess stuff happening, your base_url needs to be set properly.
There is a very simple solution go to config/constants and define SITE_URL there and set its value to
http://localhost/myprojectname/index.php.
Then use it here like this.
<?php echo anchor(SITE_URL.'/profile', 'PROFILE'); ?>

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.

Resources