Welcome Guest, Not a member yet? Register   Sign In
CI 4 Session Iframe Protected
#1

(This post was last modified: 04-06-2022, 09:56 AM by gra.)

I am trying to call an iframe of my site on CI4 with session control. 
The session is set but when I switch to the controller I don't read the username variable.
Code:
<iframe id="iframeid" name="iframe" src="http://mysite.loc/?session_username=<?php echo $_SESSION['session_username'];?>&password=<?php echo $_SESSION['password'];?>" width="100%" height="500"/>

Set Session:
PHP Code:
        if (null !== $this->request->getVar("session_username")){
            $data["session_username"]= strtoupper($this->request->getVar("session_username"));
        } else {
            $data["session_username"]="";
        }
        

        
if (null !== $this->request->getVar("password")){
            $data["password"]= $this->request->getVar("password");
        } else {
            $data["password"]="";
        }
        $Login= ['username'  => $data["session_username"],'logged_in' => TRUE]; 
PHP Code:
        $this->session->set($Login);
        $this->session->username// ok read username 

here if I read the session is read correctly.

If I switch to another controller the session is no longer read, but only with iframe, if I use the main project with CI4 the session is read correctly.
The other controller:

PHP Code:
if(isset($this->session->username)){

  $this->Main();


Do I have to set up the CI4 configuration specifically to use iframe ??


Code:
id ip_address timestamp data
Iframe send data
orbpspifh14ef6gi9dj67gdlpcpm238v 127.0.0.1 2022-04-06 18:32:56 [BLOB - 293 B]
a1pg5md365h4jae2oqhtmbg9h2mmvcfg 127.0.0.1 2022-04-06 18:32:56 [BLOB - 34 B]
Project CI4 
gv6gnm04pqlpp2nahr2eekvm0va9g2ae 127.0.0.1 2022-04-06 18:51:13 [BLOB - 369 B]


I noticed that the session is reset and creates a new one.
only with iframe.
the first two.
if I use the original project it creates only one session and is kept.
The last one.
Reply
#2

Asides from the issues with iframes, I was wondering if this was an urlencode issue?
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#3

(04-06-2022, 12:13 PM)ignitedcms Wrote: Asides from the issues with iframes, I was wondering if this was an urlencode issue?

I don't know much about urlencodes, but taking a look around is essentially passing variables to a certain function.
From what I can see under the iframe, I lose the session and the data, it is as if it no longer communicates with the framework and creates a new instance.
While if I use it from the codeigniter project everything works.
Are you telling me I need to add index.php or change a path?
Reply
#4

Modern browsers do not sent Cookie in iframe.
Is the site which has iframe the same site?

CI4 set SameSite=Lax in Cookie.
See https://github.com/codeigniter4/CodeIgni...e.php#L100
Reply




Theme © iAndrew 2016 - Forum software by © MyBB