/    Sign up×
Community /Pin to ProfileBookmark

Browser redirect doesn’t seem to work

Here’s the script as I’ve edited it from the template. The only things I’ve changed are what it says should be edited. I’ve received the test emails i’ve sent through the form attached to the mailer, just that I don’t know why the redirect doesn’t work.

the signup page is here: [url]www.sewa-ashram.org/signup.html[/url]

p.s that website is being reconstructed – the terrible html is not my handiwork!

[code=php]<?PHP

#######################################################
# This script is Copyright 2003, Infinity Web Design #
# Distributed by http://www.webdevfaqs.com #
# Written by Ryan Brill – [email protected] #
# All Rights Reserved – Do not remove this notice #
#######################################################

## The lines below need to be edited…

###################### Set up the following variables ######################
#
$to = “email@domain”; #set address to send form to
$subject = “Newsletter Signup”; #set the subject line
$headers = “From: Form Mailer”; #set the from address, or any other headers
$forward = 1; # redirect? 1 : yes || 0 : no
$location = “http://www.sewa-ashram.org/index.html”; #set page to redirect to, if 1 is above
#
##################### No need to edit below this line ######################

## set up the time ##

$date = date (“l, F jS, Y”);
$time = date (“h:i A”);

## mail the message ##

$msg = “Below is the result of your feedback form. It was submitted on $date at $time.nn”;

if ($_SERVER[‘REQUEST_METHOD’] == “POST”) {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}

mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header (“Location:$location”);
}
else {
echo “Thank you for submitting our form. We will get back to you as soon as possible.”;
}

?> [/code]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@FangMar 11.2007 — You have forgotten the hidden input:&lt;input type="hidden" name="form_thankyou" value="http://www.YOURSITE.com/THANKYOUPAGE.HTML" /&gt;&lt;br /&gt;
Copy linkTweet thisAlerts:
@ZepharimauthorMar 11.2007 — Hmm, call me part of the 98% with chimp DNA, but where do I put that? I'm not exactly experienced in this. I tried putting it in the form field and at the end of the php script, but didn't seem to make a difference. :o
Copy linkTweet thisAlerts:
@FangMar 11.2007 — Use the original from the sticky and just change the action value to your PHP script and the hidden input value to your redirect page.
Copy linkTweet thisAlerts:
@bokehMar 11.2007 — Don't use that script, it's unsafe.
Copy linkTweet thisAlerts:
@ZepharimauthorMar 11.2007 — no dice... it still doesn't redirect. Is there something wrong with this form?

[code=html]<form action="http://www.sewa-ashram.org/mailer.php" method="post">
<input type="hidden" name="form_email" value="[email protected]" /><br>
<input type="hidden" name="form_thankyou" value="http://www.sewa-ashram.org/index.html" /><br>
<b>Newsletter Signup</b><br>
<br>
Name: <input name="name" type="text" size="33" maxlength="50">
<br>
<br>
Email: <input name="email" type="text" size="33" maxlength="50">
<br>
<br>
<input type="submit" value="Submit" />
</form> [/code]


Something tells me that the redirect is going wrong in the mailer.php part, but I have no idea really.
Copy linkTweet thisAlerts:
@FangMar 11.2007 — Don't use that script, it's unsafe.[/QUOTE]Have you one for him that prevents injection? A nOOb has to start somewhere; the script from [B]pyro[/B] shows the basic functionality.
Copy linkTweet thisAlerts:
@ZepharimauthorMar 11.2007 — Don't use that script, it's unsafe.[/QUOTE]

hmm, in what way is it unsafe, and what are my alternatives?
Copy linkTweet thisAlerts:
@ZepharimauthorMar 12.2007 — from what I understood by this post, it is not necessary to use the hidden inputs from the first form, as the php file should handle the redirecting. He does say in his post you use the first form and then his mailer.php file, OR use the php code he provides. He didn't specify that you need to use the first form if you have your own php file implemented. I'm a little unclear on this still, as the redirect is not working whether those 2 lines are there or not, so surely the redirect problem is with the php, and not the form?

My knowledge of this is basic, but shouldn't these parts of the php code handle the redirect, regardless of what is entered in the form?

[code=php]$location = "thankyou.htm"; #set page to redirect to, if 1 is above

mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");[/code]


Any clarification would be great.
Copy linkTweet thisAlerts:
@ZepharimauthorMar 12.2007 — Ah well, I worked around it by making the mailer.php into a thankyou and link-back page to the main site.

[code=php]
$forward = 0;

mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location : $location");
}
else {
?>
Thank you for subscribing to our Newsletter. <a href="http://www.sewa-ashram.org">Click here to return to Sewa Ashram</a>
<?PHP
}
?>[/code]


But would still like to know why the redirect didn't work.
Copy linkTweet thisAlerts:
@FangMar 12.2007 — This line:[code=php]$location = "thankyou.htm"; #set page to redirect to, if 1 is above [/code]
×

Success!

Help @Zepharim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...