CodeIgniter Forums
Getting session status - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Getting session status (/showthread.php?tid=78912)



Getting session status - Hope - 03-26-2021

Hello there

I'm not familiar with Codeigniter and i have bought script that is made using this. However i wanted to create pages in another language.

structure currently is

example.com
example.com/es
example.com/fr

i just created subfolder to root and i have url structure as above working. But i'm unable to access sessions or is used logged in. I haven't ever used any frameworks so i really don't understand how this works. I have been reading docs about sessions and i don't know if i would need to check user status with cookies, $_SESSION or some db query.

Below is code from theme folder where i took view and header data for my language pages. There is this check with session('uid') that i cannot access from subfolders i created on root

Code:
<?php if (!session('uid')) {  ?>
    <a href="auth/login>">Login</a>
    <a href="auth/signup">Sign up</a>
    <?php }; ?>

<?php }else{?>
    <a href="Dashboard" >Dashboard</a>
<?php }?>


Seems so simple. If not session uid then show login and signup links and if session uid is created show dashboard link. What would i need to do to just get that session uid?

edit: Fixed code area


RE: Getting session status - Hope - 03-29-2021

Finally i think i got it working. As i studied how this works i now have language folder in app/modules path. I removed it from root as i wasn't able to get session no matter what i tried.

I stripped some controller to bare minimum to just display my index file.

Code:
$this->load->view('index');

In my models there are all from another module but it seems not to do anything so i just leave those there for now. Maybe i could remove almost all those as well.

I added this folder to router files so it will add only language code at the end of url

example.com/es

And now i can just make a copy of that folder, rename files and add route for another language. I'm certain there would be much better way.


RE: Getting session status - Hope - 04-01-2021

I noticed that this language page is not accessible if user is not logged in. Does someone have idea where i should do edit to allow access for everyone.

Can models file mess access as i havent made edits to it? It might been some user dashboard related page so it would be only accessible to users those are loggedin


RE: Getting session status - InsiteFX - 04-02-2021

Your model files are the files that access your database to pull in the business logic of
your application you better leave those alone. and changing any files in the application
is going to change the way it works.

To make it accessible to everyone you need to find the default controller and allow access
to everyone there. You can find the default controller by looking in the config/routes.php file
under the app or application folder CodeIgniter 3 it is application and CodeIgniter 4 it is app.