aladiyat23 Posted July 13, 2006 Share Posted July 13, 2006 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/14500-echo-url/ Share on other sites More sharing options...
pixy Posted July 13, 2006 Share Posted July 13, 2006 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); Quote Link to comment https://forums.phpfreaks.com/topic/14500-echo-url/#findComment-57421 Share on other sites More sharing options...
aladiyat23 Posted July 13, 2006 Author Share Posted July 13, 2006 ah man, that looks like a lot for this newbie here! lolUnfortunately I don't know where all of that goes. Quote Link to comment https://forums.phpfreaks.com/topic/14500-echo-url/#findComment-57426 Share on other sites More sharing options...
pixy Posted July 13, 2006 Share Posted July 13, 2006 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); Quote Link to comment https://forums.phpfreaks.com/topic/14500-echo-url/#findComment-57437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.