Jump to content

if submit redirect...


wiredphp

Recommended Posts

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?

Link to comment
Share on other sites

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

};
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

 

 

Link to comment
Share on other sites

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

};

?>

Link to comment
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.