#1
Posted 05 February 2013 - 07:36 AM
#2
Posted 05 February 2013 - 08:05 AM
What you really should do is to restructure your site. Put all of the PHP code that processes data at the top of the page, and don't send out anything to the client until you've parsed all of the PHP code. Doing it this was removes a lot of artificial limits that you've imposed on the code, by mixing HTML and PHP, and it will make your life a lot easier in the future.
#3
Posted 12 February 2013 - 07:02 AM
#4
Posted 12 February 2013 - 07:13 AM
It's not that, the header must be put before any output and I need to redirect after some output, I am currently using javascript window.location but need something else in phpThere may be any bug or error in site. According to me, make changes in code or change the site pages.. Or reinstruct.
#5
Posted 12 February 2013 - 08:00 AM
... but need something else in php
There is nothing else. header() is how you do a redirect from within PHP. Your options are either re-structure your code so you can use header() or continue using a workaround like JS.
Did I help you out? Feeling generous? I accept tips via Paypal or Bitcoin @ 14mDxaob8Jgdg52scDbvf3uaeR61tB2yC7
#6
Posted 14 February 2013 - 05:56 AM
#7
Posted 17 February 2013 - 11:06 PM
could you post the code a little bit so we can solve itI followed the procedure stated in the earlier reply, but now it is giving me a scripting error.
#8
Posted 26 February 2013 - 09:35 PM
You could use a meta refresh, can also place a die() or exit() after it
<meta http-equiv="refresh" content="0;URL='http://mysite.com/'">
Dynamic search index of websites, links, feeds, title, description, keywords and thumbnail snapshot.
#9
Posted 27 February 2013 - 05:09 AM
It's not that, the header must be put before any output and I need to redirect after some output,
That makes no sense. Why are you outputting anything if all you are going to do is try and redirect the user to another page?
You need to fix your logic.
http://thorpesystems.com | http://proemframework.org | http://github.com/trq
SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
#10
Posted 27 February 2013 - 06:42 AM
header () function in PHP. As hinted to by the meta-tag's name http-equiv:header ("Refresh: 5; URL=<a href="http://mysite.com/">http://mysite.com/</a>");
Edited by Christian F., 27 February 2013 - 06:43 AM.
#11
Posted 03 March 2013 - 11:13 PM
That makes no sense. Why are you outputting anything if all you are going to do is try and redirect the user to another page?
You need to fix your logic.
There are situations when you need to put the header after some output code in a page or within an if condition after some output or multiple headers in a piece of code for which this is required
#12
Posted 04 March 2013 - 02:59 AM
The trick is that you do not send anything to the screen/browser, until everything has been processed by PHP. At which point any headers that needs to be sent has been sent a long time ago, and you know exactly what needs to be sent to the browser.
Templating engines utilize this logic separation, and as such it might be a good idea to study up on them. Should help you write even better code, even if you choose not to use one for a project.
#13
Posted 04 March 2013 - 03:38 AM
No, there are no such situations. At least not if you've written the code properly, with separated business logic and presentation logic.
The trick is that you do not send anything to the screen/browser, until everything has been processed by PHP. At which point any headers that needs to be sent has been sent a long time ago, and you know exactly what needs to be sent to the browser.
Templating engines utilize this logic separation, and as such it might be a good idea to study up on them. Should help you write even better code, even if you choose not to use one for a project.
OK got that thank you!
#14
Posted 04 March 2013 - 01:43 PM
#15
Posted 05 March 2013 - 06:35 PM
It may also be worth noting (and correct me if im wrong here)
You can enable output buffering, at which point PHP Header functions will not be limited to Pre-Content execution.
Christian is right though, it is best practice to keep your redirects prior to page content.
Just thought id weigh in.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












