Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.