Jump to content

echo url


aladiyat23

Recommended Posts

hi, i've posted here before... but for this project the solution given wont work...

I would like any help with redirecting to a url on submit, after checking for errors... the form works perfect with the code below:

mail($to, $subject, $body, $headers);
echo "Your message has been sent to xxxxx. Thank you for your inquiry. One of our friendly sales staff will be in touch with you soon";
} else {
echo "An error has occured. Please fill out the form and try again";
}
?>

Any help to replace that message with a url redirect would be appreciated :)

Thanks!!!
Link to comment
https://forums.phpfreaks.com/topic/14500-echo-url/
Share on other sites

A url redirect?
Well, I made myself a function so that I dont have to worry about headers already sending since my website uses sessions and you're supposed to use header("Location: link.php"); or something like that...

function redirect($path, $timeout=2, $type=X_REDIRECT_HEADER) {

    // Make sure the session isn't split
    if (strpos(urldecode($path), "\n") !== false || strpos(urldecode($path), "\r") !== false)
    {
        error('Tried to redirect to potentially insecure url.');
    }

    // force session to be written before redirecting
    session_write_close();

    $type = (headers_sent() || $type == X_REDIRECT_JS ) ? X_REDIRECT_JS : X_REDIRECT_HEADER;
    if ($type == X_REDIRECT_JS) {
        ?>
        <script language="javascript" type="text/javascript">
        function redirect() {
            window.location.replace("<?php echo $path?>");
        }

        setTimeout("redirect();", <?php echo ($timeout*1000)?>);
        </script>

        <?
    } else {
        if ( $timeout == 0) {
            header("Location: $path");
        } else {
            header("Refresh: $timeout; URL=./$path");
        }
    }
    return true;
}

Then, when I want to redirect, I just use this:
redirect("link.php", 0);
Link to comment
https://forums.phpfreaks.com/topic/14500-echo-url/#findComment-57421
Share on other sites

Just put it at the top of whatever page you're using.

Or, create functions.php and put it in there. Then, just include it in every page you want to use the redirecting function in.

include("functions.php");

That way, you don't even have to worry about it. Just use the function to redirect.
redirect("page.php", 0);
Link to comment
https://forums.phpfreaks.com/topic/14500-echo-url/#findComment-57437
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.