Page 1 of 1
function for redirect
Posted: Mon May 17, 2004 7:09 pm
by competent
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
Posted: Mon May 17, 2004 7:17 pm
by markl999
You could use an
html meta-refresh
Yeah but...
Posted: Mon May 17, 2004 7:30 pm
by competent
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
Posted: Mon May 17, 2004 7:32 pm
by dull1554
acctually it's suppose to be in the head but it will work anywhere in the page, a bit messy but i use em all the time rather then header redirects
Posted: Mon May 17, 2004 7:32 pm
by markl999
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?
Posted: Mon May 17, 2004 7:40 pm
by competent
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>
Posted: Mon May 17, 2004 7:42 pm
by tim
how about javascript?
<script language=javascript>location.replace('
http://www.disneyland.com')</script>
Posted: Mon May 17, 2004 7:47 pm
by competent
Yeah maybe, but what if sb doesn`t have javascript enabled??

Posted: Mon May 17, 2004 7:55 pm
by tim
lol then perhaps your asking the impossible
=]
Posted: Mon May 17, 2004 8:02 pm
by dull1554
you could set a time delay.....
Code: Select all
<meta http-equiv="refresh" content="time in seconds" url="url">
Posted: Mon May 17, 2004 8:14 pm
by jason
*cough* *cough*
Code: Select all
<?php ob_start(); ?>
<body>
<?php
header("Location: some_page.php");
?>
</body>
[php_man]ob_start[/php_man]
Behold, the power of output buffering.
Posted: Tue May 18, 2004 2:28 pm
by hedge
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.
Code: Select all
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.
Posted: Sun Jun 20, 2004 6:57 pm
by John Cartwright
i like that function hedge...
im slightly using it on my user authentication script