Welcome Guest, Not a member yet? Register   Sign In
Sessions - Bug?
#11

[eluser]amw_drizz[/eluser]
I used your recommendations and I still get the same error. header output started and sessions failed...
#12

[eluser]majidmx[/eluser]
What you have in :
main_site\controllers\auth.php
Line 18 ?

There should be some out put which prevents the headers from being started.
#13

[eluser]amw_drizz[/eluser]
?> the end of the document...
#14

[eluser]majidmx[/eluser]
ok, so you have some extra spaces after ?>,
try to delete whatever is after the ?> including any space, line etc and save the file.
#15

[eluser]Fierymind[/eluser]
I confirm this post, when using sessions in models, it fail "sometimes".

I'm building some software for a company, and while the software is working fine from my office computer, there was no way for software to work in company office!

software simply can't write any cookies and after some debugging, I found the "Cannot modify header information - headers already sent ..." error.

There is no way to solve this problem at company office and suddenly it works (no code modification happen, no ?> in any PHP file).

after 100s of trails in many computers in the company, I got the result sessions "sometimes" work ... I hate the word "sometimes" in programming.

anyways, I read this post and put the session work in the controller instead of model, uploaded the new stuff and called the company to try again .. they tried everything and program did NOT fail even once.

So I guess, sessions does NOT work probably within model, I think this must be included in CI manual.

(I'd like to thank everyone behind the CI project, CI is PERFECT PHP framework, and I hope to find a way to return the favor to CI producers and community)
#16

[eluser]The Wizard[/eluser]
HELLO Smile

1. the cannot modify header error is releated to something getthing echo'ed before the session
or a redirect, anyway before something that puts out an 'header'.

2. in my case, it really didnt work sometime BUT

i didnt notice, that sometimes i tryed on localhost and sometime's on the ip 127.0.0.1
which both point to the dev server but THEY ARE NOT THE SAME DOMAIN which for me,
caused the session to fail "sometimes" Smile

could you check that and write us back?

btw. i also tryed to load a model in a function, when i needed it, but it actually didnt work
so i had to load it in the constructor, EVEN IF IT WAS NOT NEEDED IN ALL FUNCTIONS so there
MIGHT be an issue with these at all.

we will seeSmile
#17

[eluser]Fierymind[/eluser]
well, the "sommtimes" failure drive me crazy, but here is some info in my case, may that help:

- we do try this on live web server with live domain name
- there is NO output before cookie/session work and I know what I'm talking about.

here is the user/password verification function

Code:
function verifyUser($u,$pw){
        
        $this->db->where('user_name',$u);
        $this->db->where('user_pass', md5($pw));
        $Q = $this->db->get('users');

        if ($Q->num_rows() > 0){
            $row = $Q->row_array();
            $something = $this->session->set_userdata('user_id',$row['user_id']);
            $this->session->set_userdata('user_name',$row['user_name']);
            $this->session->set_userdata('access_level',$row['access_level']);
            return TRUE;
        }else{
            
            return FALSE;
        }        
    }

if we put this function in model 'muser', and called it from 'user' controller like :

Code:
if (!$this->muser->verifyUser($_POST['username'],$_POST['password']))
{ /*you are not loged */ } else {/* you loged*/}

it will "sometimes" fail to write the cookie

but if I put the same function in controller 'user' itself and called it like

Code:
if (!$this->verifyUser($_POST['username'],$_POST['password']))
{ /*you are not loged */ } else {/* you loged*/}

it works allllll the time.

please note that session lib and all models are autoloaded.
#18

[eluser]The Wizard[/eluser]
1. do you have some blank space AFTER a ?&gt; <-- somewhere?
2. are you sure, you use 1 ADDRESS ONLY? like http://LOCALHOST OR http://127.0.0.1 ?
#19

[eluser]majidmx[/eluser]
As herrkaleun pointed it out, it could be a cookie_domain problem.
check your config file for
Code:
$config['cookie_domain']
I spend a lot of time for one of my project to figure out why cookies are not working on my machine ! in that case I had set the cookies domain to the domain of our production server.
#20

[eluser]Fierymind[/eluser]
- I'm using live domain name, so there is no chance to use IP in mistake Smile
- I do not use ?&gt; in any PHP file

as of config file, I see I'm using the default setting

Code:
$config['cookie_domain']    = "";

but I never modified this before in any project AND I see software works great now after moving the session code in to the controller file with this value set to default ..

If you really think $config['cookie_domain'] is that important, then I think CI must generate the value of it from $config['base_url'] or at least mention it as REQUIRED config item

also, in config file:
Code:
/* | 'cookie_domain' = Set to .your-domain.com for site-wide cookies */

does that means, I have to use . infornt of domain ? to be like

Code:
$config['cookie_domain']    = ".something.com";


or this . is just a typo?




Theme © iAndrew 2016 - Forum software by © MyBB