Welcome Guest, Not a member yet? Register   Sign In
file_get_contents question with CI
#1

[eluser]coolant[/eluser]
I am calling CI pages through ajax through a simple
Code:
echo json_encode ( array ( 'html' => file_get_contents('http://site/' . $_POST['page'] ) ) );

In the page that's being called, all the text displays - but when I try to access CI session, I get nothing back from the CI session. I tried ...

Code:
$this->CI =& get_instance();
echo $this->CI->session->userdata('uid');
echo 'test';

But all I get back is "test". I know session->userdata('uid') is set because I use it on other pages. When I directly go to the page, the session works - but it seems like a problem with file_get_contents.

Any ideas?
#2

[eluser]nikefido[/eluser]
It is probably creating a new session based on the ajax calling the site without the "www" vs a site with the "www"

For instance, if you are at "http://www.mysite.com" but your ajax is calling "http://mysite.com", you might get 2 sessions started there - a new session created for your ajax call.

This can also happen with http vs https (but using ajax with "http" vs "https" creates a JS security error in my experience)

As a side note, why are you using file_get_contents? This could totally be my ignorance, but I've only seen that used when reading local files (ajax calls return the entire HTML output of their server requests, so file_get_contents seems unnecessary to me)




Theme © iAndrew 2016 - Forum software by © MyBB