Jump to content


Photo

echo url


  • Please log in to reply
3 replies to this topic

#1 aladiyat23

aladiyat23
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 13 July 2006 - 04:25 PM

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

#2 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 13 July 2006 - 04:34 PM

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);

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#3 aladiyat23

aladiyat23
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • Locationflorida

Posted 13 July 2006 - 04:38 PM

ah man, that looks like a lot for this newbie here! lol

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



#4 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 13 July 2006 - 04:49 PM

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);

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users