Page 1 of 1

Cookie not created

Posted: Fri Aug 14, 2009 3:22 pm
by tecktalkcm0391
I have a class and in it there is a function that makes a cookie:

Code: Select all

class login {
    
    function setCompanyId($company_id){
        setcookie('company_id', $company_id, 2592000 + time() );
    }
}
And it never seems to be created. Any ideas why? And how to fix it?

Re: Cookie not created

Posted: Fri Aug 14, 2009 3:25 pm
by jackpf
What does

Code: Select all

print_r($_COOKIE);
show?

Also, try setting the cookie with the path and domain name as well. It shouldn't make any difference, but you never know...

Re: Cookie not created

Posted: Fri Aug 14, 2009 3:53 pm
by tecktalkcm0391
The output shows only

Code: Select all

Array ( [token] => fd3f90c46f59b53832578ed188d5156b )
Token in the PHP Session Name.

Any more ideas, I added the path and domain name too, no luck.

Re: Cookie not created

Posted: Fri Aug 14, 2009 3:58 pm
by jackpf
Have you got error reporting turned on? Are you calling this function before anything is output to the page?

Re: Cookie not created

Posted: Fri Aug 14, 2009 4:04 pm
by tecktalkcm0391
I had ob_start running which hide the header errors, but I am getting "headers already sent by" message. Is there anyway to find out where its coming from, cause the line it says, it tells me it the setcookie() line. Anyway to work around it?

Re: Cookie not created

Posted: Fri Aug 14, 2009 4:08 pm
by jackpf
What's the exact error?

Re: Cookie not created

Posted: Fri Aug 14, 2009 7:35 pm
by tecktalkcm0391
A line of code above the line with the cookie was causing the error. Thanks though :)

Re: Cookie not created

Posted: Fri Aug 14, 2009 11:23 pm
by jackpf
Ahh right. Cool. No problem.