Is there any method available by which i can REDIRCET to another page anywhere in the PHP after HTML output ??? I have seen several solutions with PHP + Javascript… is there any way t do this 100% in PHP ?? Becasue there are browsers which do not suppors JavaScript, or the USer has just DISABLED JavaScript ??? Please help
If you are talking about redirecting after the page has been rendered you can not do this with PHP, as PHP is on the server and runs before the page is rendered. If you want the page to redirect based on user inter-action then you can use javascript (or maybe vbscript too?). If you simply want a timed redirect you can use a meta tag eg.
That’s an interesting question, and one I’ve struggled with many times my self. Yes I too try and avoid Javascript redirects on public pages, using a php header redirect after output doesn’t work, and yes simple meta redirecting certainly has downsides. I go the meta refresh route, I just make it a decent length of time, so the switch is not super abrupt, and also place an href link so users do not have to wait if they do not want to. Really clumsy, and if someone has another solution, I’d love to hear it.
Yes there are issues with the meta tag. This is apparent particularly on websites where you are transfering confidential informatin across the internet, for example, buying things. If you are using the meta tag, be sure you give the user at least 10 seconds, and give them the option (via a link) to skip the refresh and go straight to the next page. It will give them more confidence.
HI Participents. Thanks for your replys here.
I would like to add some thing. People, in ASP we have “resonse.redircet…” which i think works even after the HTML OUTPUT. And uptill now, ( I HAVE A VERY LIL KNOWLEDGE OF THIS) but I feel that PHP is much STRONGER than ASP. Than WHY PHP DO NOT HAVE SUCH FACILITIES ??? Moreover, I have got only 1 response with “ob_start();” is that a GOOD SOLUTION ???
I was the only one who mentioned ob_start as everyone was unsure quite what you were asking.
Output buffering was designed to solve the problem of sending headers (e.g. header location redirects) even after “sending” output to the browser… From PHP.net:
The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo() and data between blocks of PHP code.
Try putting output buffering into your script and see if that solves the problem you were having. Output buffering makes it so that your output is sent at the end of your script’s execution as opposed to when it is generated during the execution.
I would say that actually ASP is “stronger” than PHP. It is the language of choice for corporate intranets where typically you have a great deal of web based applications.
However for internet I think PHP much more suitable, it is much easier on server system resources, with the upgrades in PHP5, it is giving ASP some real competition, but I still say using ASP for internet stuff is akin to using a shotgun to kill flies, it will do it, but it’s unnecessarily powerful.
Moreover you received almost a dozen responses and as you say only one response with “ob_start();”. If you think that is the only solution of any merit, you seem to have a good idea about the answer to your own question, so why did you ask it in the first place? It certainly sounds like the best solution, but certainly not the only one offered. Perhaps it was only mentioned by one person, because only one person is familiar with it. If you’re going to display such a massive level of ingratitude, I would strongly recommend sticking to what you know!
Using the buffer functions is unavoidable in some situations. As a “buffer” uses memory resources (probably not that big of a deal) I try to avoid using it unless absolutely necessary. For example, intead of