[ Login Redirect PHP with Special Function ]
I have the following function set up in my includes and class file:
function makeMessage($message, $href, $onclick = '', $redirect = '', $linktext = 'Click here to continue') {
echo "<center>";
echo "<strong>" . $message . "</strong><br><a href=\"" . $href . "\" onClick=\"" . $onclick . "\" class=\"button\">" . $linktext . "</a>";
if (! empty ( $redirect ))
echo "<br><meta http-equiv=\"refresh\" content=\"" . $redirect . "\"><strong>You should be redirected within a few seconds...</strong>
<br><br>Or let's <a href=\"delivery_info.php\">check out now!</a>";
echo "</center>";
}
However, on my register and login, add to order all uses this function, but I'm unsure what broke. Here's how I'm using it:
if ($post ['price_id'] == 0) {
$WALM->makeMessage ( 'You are now logged in!', 'order_now.php', '', 'order_now.php' );
} else {
}
The problem is, that it's not working with the meta refresh, does anyone have any help here to change this about and to what?
Answer 1
Use header()
instead of <meta>
function makeMessage($message, $href, $onclick = '', $redirect = '', $linktext = 'Click here to continue') {
echo "<center>";
echo "<strong>" . $message . "</strong><br><a href=\"" . $href . "\" onClick=\"" . $onclick . "\" class=\"button\">" . $linktext . "</a>";
if (! empty ( $redirect )) {
header("refresh:5;url=$redirect");
echo "<br><strong>You should be redirected within a few seconds...</strong>
<br><br>Or let's <a href=\"delivery_info.php\">check out now!</a>";
}
echo "</center>";
}
Answer 2
tags should be placed within the section. Maybe it's the problem? You could try a JS redirect as follow:
function makeMessage($message, $href, $onclick = '', $redirect = '', $linktext = 'Click here to continue') {
echo "<center>";
echo "<strong>$message</strong><br/><a href=\"$href\" onClick=\"$onclick\" class=\"button\">$linktext</a>";
if (!empty ($redirect))
echo "<br>
<script type=\"text/javascript\">
window.location = \"$redirect\"
</script>
<strong>You should be redirected within a few seconds...</strong>
<br><br>Or let's <a href=\"delivery_info.php\">check out now!</a>";
echo "</center>";
}
EDIT
You can not send headers considering that the redirect is not to the top of the page. If you want to delay the redirect, you can use the setTimeout() JS function