Welcome Guest, Not a member yet? Register   Sign In
Server error, redirects and flashdata
#1

[eluser]gregormck[/eluser]
Hi there,

I'm having issues with 500 errors and have narrowed it down to setting flashdata and redirect. I have the following code:
Code:
$account_message = "Your currency settings have been updated";
$this->session->set_flashdata('account_message', $account_message);
redirect('settings/account/');

If I change the currency settings (which is done on /settings/account) then they change in the DB and the user is redirected to the /settings/account page and presented with the flashdata message

However, if I change the currency again I get "An internal server error occurred".

If I comment out:

Code:
$this->session->set_flashdata('account_message', $account_message);

It works and I get no errors.

This is the same issue with many other parts of my application where I set flashdata, redirect and then perform the post action again.

Any ideas what could be going on?

Some other details include:

htaccess:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

URI Protocol:

Code:
$config['uri_protocol'] = 'ORIG_PATH_INFO';
#2

[eluser]Aken[/eluser]
What's your server setup? PHP version? When you receive the error, does the page take forever (like its timing out)?

It seems odd that you'd be getting 500 errors from the sessions class. Maybe you can debug the set_flashdata method to see which part is causing the error - might help you narrow down what it's conflicting with.
#3

[eluser]skunkbad[/eluser]
I don't think you can effectively set cookie data right before a server redirect. If you look at some other threads here in the CI forums, you will see that some browsers will let you do it, but it is buggy. This is not a CI issue, but just common sense when considering the true nature of how HTTP requests work.
#4

[eluser]Aken[/eluser]
His problem is giving him 500 server errors, though. Not just losing the value, which is the problem most people face. Would the two be related?
#5

[eluser]skunkbad[/eluser]
[quote author="Aken" date="1333767450"]His problem is giving him 500 server errors, though. Not just losing the value, which is the problem most people face. Would the two be related?[/quote]

Well, I don't know. Actually, I was just reading the php docs, and it looks like you need to set the cookie after the redirect. I'm on an ipad or i would type more, but I think it might be worth trying to move the line of code that sets the cookie below the redirect,
#6

[eluser]toopay[/eluser]
Start trace your problem from your web-server error log.
#7

[eluser]gregormck[/eluser]
Thanks everyone for the comments. I've done a lot of digging in the past day or so and it appears that many others have sessions / flashdata issues.

I'm running php5.3 on a grid service (third party host - linux, apache), which has caused me a few .htaccess challenges in the past with EE, but agree with @skunkbad on setting the data before a redirect. I've tried different combinations and settings, but the errors are still happening (with many irregularities).

If I remove the use of flashdata across the app then I get no other errors - which has got me wondering what the point of flashdata is (if I'm not the only one with issues like this)!

So I'm now removing the use of flashdata (and will revisit later). Will investigate the use of native sessions functions too - as may be more reliable.

#8

[eluser]Aken[/eluser]
Yeah, if you want to figure out why that function is causing errors, pick apart the set_flashdata() method until you find the chunk that's messing things up, and see why it's not agreeing with your server.
#9

[eluser]gregormck[/eluser]
Hi folks - just to let you know; I started storing the session data in the database (rather than in a cookie - which I didn't realise was the case initially) and that sorted the errors out. So flashdata is now working - which is a better solution than having no flashdata working!
#10

[eluser]Aken[/eluser]
How much other session data are you storing? Maybe you were getting errors from data being cut off in the cookies, since they only handle up to 4kb of data (I think that's the amount - something like that).




Theme © iAndrew 2016 - Forum software by © MyBB