wiredphp Posted August 16, 2012 Share Posted August 16, 2012 so here is my code: <?php if(!isset($_POST['submit'])) { $ToEmail = 'ndneasystems@yahoo.com'; $EmailSubject = 'Pitanje sa ndnea.com'; $mailheader = "From :". $_POST["email"]. "\r\n"; $mailheader .= "Reply to :". $_POST["email"]. "\r\n"; $mailheader .= "Ova poruka sadrzi pitanje postavljeno na www.ndnea.com \r\n"; $MESSAGE_BODY = "Ime : " .$_POST["name"]." \r\n"; $MESSAGE_BODY .= "Email : " .nl2br($_POST["email"])." \r\n"; $MESSAGE_BODY .= "Naslov : " .$_POST["subject"]." \r\n"; $MESSAGE_BODY .= "Poruka : " .nl2br($_POST["feedback"])." \r\n"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); echo "Vasa poruka je uspjesno poslana! Kliknite <a href=\"index.html\">ovde</a> za pocetnu stranu "; }; ?> so what I want to do is, when user submited form to be redirected to contact page... any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/ Share on other sites More sharing options...
floridaflatlander Posted August 16, 2012 Share Posted August 16, 2012 so here is my code: <?php if(!isset($_POST['submit'])) { $ToEmail = 'ndneasystems@yahoo.com'; $EmailSubject = 'Pitanje sa ndnea.com'; $mailheader = "From :". $_POST["email"]. "\r\n"; $mailheader .= "Reply to :". $_POST["email"]. "\r\n"; $mailheader .= "Ova poruka sadrzi pitanje postavljeno na www.ndnea.com \r\n"; $MESSAGE_BODY = "Ime : " .$_POST["name"]." \r\n"; $MESSAGE_BODY .= "Email : " .nl2br($_POST["email"])." \r\n"; $MESSAGE_BODY .= "Naslov : " .$_POST["subject"]." \r\n"; $MESSAGE_BODY .= "Poruka : " .nl2br($_POST["feedback"])." \r\n"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); echo "Vasa poruka je uspjesno poslana! Kliknite <a href=\"index.html\">ovde</a> za pocetnu stranu "; header("Location: $home/member/index.php"); // or what ever exit(); }; ?> Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1369845 Share on other sites More sharing options...
floridaflatlander Posted August 16, 2012 Share Posted August 16, 2012 Hey I just saw your echo, why the echo if you want to redirect? Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1369847 Share on other sites More sharing options...
wiredphp Posted August 16, 2012 Author Share Posted August 16, 2012 echo is there because I didn't know how to redirect, so I put it there so that users can return to page, and not to see blank page... Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1369848 Share on other sites More sharing options...
floridaflatlander Posted August 16, 2012 Share Posted August 16, 2012 Well the above should work, about a year ago I had my redirect as header("Location: ../member/index.php"); // or what ever exit(); and was told by the powers here to have a absolute paths in my redirects so I changed it to "$home/member/index.php" And $home depending on if I was on my computer or online. Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1369850 Share on other sites More sharing options...
wiredphp Posted August 16, 2012 Author Share Posted August 16, 2012 I will give it a try... I'm new to php so.... anyway, thanks, I hope that will work... Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1369852 Share on other sites More sharing options...
Christian F. Posted August 16, 2012 Share Posted August 16, 2012 Hmm.. I would actually recommend against using absolute paths, as they tend to make it more difficult to transport scripts between systems. If you have a relative path, and move servers, you don't have to do anything. Seeing as the path structure is the same within the scope of the page, but the path outside of your web root will (most likely) be completely different. You might have to adjust the URL between sites, but that's also true for absolute paths in that case. That said, you really need to validate your input, wiredphp. Your script is wide open for attackers to abuse, so that they can send spam-mail to anyone they like, by using mail header injection attacks. Yes, even if you've set the "TO:" header; The hackers just overwrite it with their own headers, it is trivial to do after all. Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1369882 Share on other sites More sharing options...
floridaflatlander Posted August 16, 2012 Share Posted August 16, 2012 Hmm.. I would actually recommend against using absolute paths, as they tend to make it more difficult to transport scripts between systems. If you have a relative path, and move servers, you don't have to do anything. Seeing as the path structure is the same within the scope of the page, but the path outside of your web root will (most likely) be completely different. You might have to adjust the URL between sites, but that's also true for absolute paths in that case. .... so I changed it to "$home/member/index.php" And $home depending on if I was on my computer or online. $home can change and alllows for an absolute path change Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1369945 Share on other sites More sharing options...
Christian F. Posted August 16, 2012 Share Posted August 16, 2012 floridaflatlander: The use of $home was not what I was commenting upon, I'm afraid, but the use of absolute paths. Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1369999 Share on other sites More sharing options...
kicken Posted August 16, 2012 Share Posted August 16, 2012 There's nothing wrong with using absolute paths, just do not hard code them. Either define a variable or a constant and use that as a prefix to relative paths. I personally find them to be easier to use/debug as you are always sure what folder/file your referencing. and was told by the powers here to have a absolute paths in my redirects so I changed it to "$home/member/index.php" And $home depending on if I was on my computer or online. The HTTP specification says that the argument to a Location: header needs to be a full URI, not a relative path. Most browsers will work with a relative URI however. I've never encountered one that didn't. So it kind of comes down to if you want to follow the spec, or if you want to just make it work. I've created a custom function called DoRedir() that will accept a relative reference, calculate the absolute URI, and then issue the header with the absolute uri. That way I can just use a relative uri throughout the code for easy of use/readability but still keep to the specification. Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1370032 Share on other sites More sharing options...
wiredphp Posted August 17, 2012 Author Share Posted August 17, 2012 Thank you. Now I will try to validate fields from form. If you know any good online tutorial of form handling please post it. And sorry for my bad english. Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1370084 Share on other sites More sharing options...
wiredphp Posted August 17, 2012 Author Share Posted August 17, 2012 so what I did for now is to see if fields are set, if not code shuld return message to enter req field. but, to do that I need to remove onBlur javascript value from contact form becuse php used default value to send it, if you know what I mean. now it dosen't look like I wanted to... is there posibility to somehow hide that default vaule? <?php if(empty($_POST["name"])) { die("Please provide valid name"); } ?> <?php if(is_numeric($_POST["name"])) { die("Please provide valid name"); } ?> <?php $email = $_POST["email"]; if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email)) { die("E-mail address not valid"); }; ?> <?php if(empty($_POST["subject"])) { die("Plese enter a subject."); } ?> <?php if(!isset($_POST['submit'])) { $ToEmail = 'ndneasystems@yahoo.com'; $EmailSubject = 'Pitanje sa ndnea.com'; $mailheader = "From :". $_POST["email"]. "\r\n"; $mailheader .= "Reply to :". $_POST["email"]. "\r\n"; $mailheader .= "Ova poruka sadrzi pitanje postavljeno na www.ndnea.com \r\n"; $MESSAGE_BODY = "Ime : " .$_POST["name"]." \r\n"; $MESSAGE_BODY .= "Email : " .nl2br($_POST["email"])." \r\n"; $MESSAGE_BODY .= "Naslov : " .$_POST["subject"]." \r\n"; $MESSAGE_BODY .= "Poruka : " .nl2br($_POST["feedback"])." \r\n"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); echo "Vasa poruka je uspjesno poslana! Kliknite <a href=\"index.html\">ovde</a> za pocetnu stranu "; }; ?> Quote Link to comment https://forums.phpfreaks.com/topic/267168-if-submit-redirect/#findComment-1370140 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.