PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hello!!!
I would like to avoid using redirection through the
<?php
header("Location: some_location.php");
?>
Is there any othher way to do this!!!
Thanks for any suggestions
I don`t want header redirect because it must be before any information is sent to browser. Meta redirect can be in <html> but only in <head> with other meta tags. So meta redirect is not the remedy for it. But thank you anyway. If you know any other kinds of redirections which can be used without warnings/errors in <body> part of the website I would be grateful
You've confused me.
You either want to redirect before any output, in which case header() will do it, or you want to display some output, then redirect, in which case a meta-refresh will do it.
What other senario do you have?
No. It`s true that meta tag works after any output is sent to browser but BEFORE <body> witch is the case. I want to redirect AFTER <body> tag, and meta tag won`t do it.
eg with header which would return error that it cannot send header info.
<body>
<?php
if(sth)
sth;
else
header("Location: some_page.php");
?>
</body>
Last edited by competent on Mon May 17, 2004 7:45 pm, edited 1 time in total.
well if you need to do that, you're logic is hooped. You should figure out what actions you need to take before you get to that point.
I have ran into cases where I cannot use a header though (usually when trying to target frames) so I use the following function, it provides a clickable link that is automatically ran with javascript but they can click if js is disabled.
function urlRedirect($url, $msg='') {
$msg .= '<br><br>Redirection In Progress. Click here if your browser does not support automatic redirection!';
header('Pragma: no-cache');
header('Cache-Control: no-cache, must-revalidate');
echo '<html>';
echo '<head>';
echo ' <style type="text/css">';
echo ' A {color:#336699; font-family:Arial; font-size: 12pt; font-weight:bold}';
echo ' </style>';
echo ' <script language="javaScript">';
echo ' function redirect() {window.parent.location=''' . $url . ''';}';
echo ' </script>';
echo '</head>';
echo '<body onload="setTimeout(''redirect()'',2000);">';
echo '<table border=0 width=100% height=100%><tr>';
echo '<td width=20%> </td>';
echo '<td width=60% align="center" valign="center"><a target="_parent" href="' . $url . '">' . $msg . '</a></td>';
echo '<td width=20%> </td>';
echo '</tr></table>';
echo '</body></html>';
exit();
}
PS. I hate sights that use meta-refresh html with a timeout of zero... when you go back through your history you get captured by that page because you have no time to click past it.