![]() |
Warning show up when using redirect($url, 'refresh'); - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Warning show up when using redirect($url, 'refresh'); (/showthread.php?tid=43962) |
Warning show up when using redirect($url, 'refresh'); - El Forum - 07-28-2011 [eluser]sangprabo[/eluser] I have modified the url_helper so MY_url_helper looks like this. Code: function redirect($uri = '', $method = 'location', $http_response_code = 302) To use it Code: echo $this->parser->parse('static_page/success_message', $data, TRUE); I'm using it on my local machine. Nothing is wrong. The message is displayed correctly. And the page will be redirected within 5 seconds. The problem is, when I upload my application to the server, it shows warning and the page is not redirected. Code: Severity: Warning My temporary solution is to create a meta tag Code: <meta http-equiv="Refresh" content="5; url={meta_redirect_url}" /> Do you guys have any better idea? Why can't I use the 'refresh' after echoing some lines of message? Thank you. Warning show up when using redirect($url, 'refresh'); - El Forum - 07-29-2011 [eluser]Vlad Balmos[/eluser] You are not allowed to output anything to the browser before sending http headers. As to why it works on your local machine i don't really know. It shouldn't work ![]() If you really need to refresh the page after outputing a message, you could try a redirect using javascript Code: [removed] Or something like that ![]() Warning show up when using redirect($url, 'refresh'); - El Forum - 07-29-2011 [eluser]sangprabo[/eluser] Thanks for your reply. I'm not using the redirect($url), but redirect($url, 'refresh'); Is it not allowed too? It's like when you perform a log in action in this forum, the message will flash for 1 second. But the code is written in meta tag. Sorry, I can't read your script code. Warning show up when using redirect($url, 'refresh'); - El Forum - 07-29-2011 [eluser]Vlad Balmos[/eluser] It doesn't matter. You are making a header request. The following is a quote from the php manual: "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file." The code i posted was escaped to prevent xss. It's plain javascript code. Search for [removed] and setTimeout function in javascript. You'll get the ideea. Warning show up when using redirect($url, 'refresh'); - El Forum - 07-29-2011 [eluser]Vlad Balmos[/eluser] [removed] = window . l o c a t i o n Warning show up when using redirect($url, 'refresh'); - El Forum - 07-29-2011 [eluser]sangprabo[/eluser] Okay, noted. But why is redirect($url, 'refresh') working flawlessly on my local machine? Your script code is good for those who activate javascript on their browser, but I prefer the meta tag. Warning show up when using redirect($url, 'refresh'); - El Forum - 07-29-2011 [eluser]Vlad Balmos[/eluser] Ok, so i did some testing on my machine and got the same results as you. It works on your machine because you must have output buffering enabled in you php configuration. Open php.ini on your local server and search for output_buffering. If it's != off then for sure output buffering is enabled. Thus, even thou you echo the message before sending the redirect header, the message gets buffered and it's actually sent to the browser after the redirect header Try this on your local machine, i'll bet it will give the same error as the production server: Code: echo $this->parser->parse('static_page/success_message', $data, TRUE); The solution is simple: echo the message after you have sent the refresh header, just reverse the order of those 2 statements: Code: redirect($redirect_url, 'refresh'); it should work. Warning show up when using redirect($url, 'refresh'); - El Forum - 07-29-2011 [eluser]sangprabo[/eluser] Thanks for your fast reply. I will try it soon on my server. |