Attending the forum dedicated to PHP often see threads where people claim to use Javascript redirects achieved because the header () function does not allow to define the duration of loading a page before the redirect to another resource.
This is absolutely not true, header () is supplying an attribute called refresh, which would set the waiting time before a redirect in number of seconds, watch for example the following list:
- <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span style=”direction: ltr; text-align: left;”> </span></span>
- <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span style=”direction: ltr; text-align: left;”>header( “refresh:5;url=index.php” );</span> header (“Refresh: 5; url = index.php”);</span>
- <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span style=”direction: ltr; text-align: left;”>echo “Se il tuo browser non supporta il redirect clicka <a href=”\”>qui</a>.”;</span> echo “If your browser does not support redirects <a href=”\”> Click here <!– a–>.”</a></span>
- <span onmouseover=”_tipon(this)” onmouseout=”_tipoff()”><span style=”direction: ltr; text-align: left;”><a href=”\”>?></a></span><a href=”\”> ?></a></span>
If the proposed redirects to page “index.php” is after 5 seconds of waiting, you can also reverse the two lines of education displayed by preventing the sending of an output before the function header () produces an error by the browser, this will be using the functions ob_start () and ob_end_flush ():
- <span onmouseout=”_tipoff()”><span class=”google-src-text” style=”direction: ltr; text-align: left;”><?php</span> <? Php</span>
- <span onmouseout=”_tipoff()”><span style=”direction: ltr; text-align: left;”>ob_start();</span> ob_start ();</span>
- <span onmouseout=”_tipoff()”><span style=”direction: ltr; text-align: left;”>echo “Se il tuo browser non supporta il redirect clicka <a href=\”index.php\”>qui</a>.”;</span> echo “If your browser does not support redirects <a href=\”index.php\”> Click here </ a>.”</span>
- <span onmouseout=”_tipoff()”><span style=”direction: ltr; text-align: left;”>header( “refresh:5;url=index.php” );</span> header (“Refresh: 5; url = index.php”);</span>
- <span onmouseout=”_tipoff()”><span style=”direction: ltr; text-align: left;”>ob_end_flush();</span> ob_end_flush ();</span>
- <span><span class=”google-src-text” style=”direction: ltr; text-align: left;”>?></span> ?></span>
Thus ob_start () diverts the flow of data to the buffer dedicated to running the application that will be freed when you call to ob_end_flush ().
Related posts: