Jump to content

Archived

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

aladiyat23

echo url

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!!!

Share this post


Link to post
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);

Share this post


Link to post
Share on other sites
ah man, that looks like a lot for this newbie here! lol

Unfortunately I don't know where all of that goes.

Share this post


Link to post
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);

Share this post


Link to post
Share on other sites

×

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.