php redirection or links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grantg
Forum Newbie
Posts: 2
Joined: Sun Sep 30, 2007 9:13 am

php redirection or links

Post by grantg »

Hello. I have created a new site, which has only had the one page uploaded live for a small test - http://www.discountgardencentre.co.uk/contact. The forum passes the data to mailer.php - which then echos "Thank you for your comments to xyz@abc.co.uk" on screen. That is the only output the code gives. It does work, as the emails are sent to our inbox. But, the problem is, it takes the user to a dead page, with no redirection back to the main site or even a link to get there. This is the code for the php file, I would like the file to redirect after 5 seconds, or display a link to say something to the effect of "Click here to return to http://www.discountgardencentre.co.ukwww.discountgardencentre.co.uk.

Code: Select all

<?php

if(!$url) { $url = 'http://www.discountgardencentre.co.uk'; } ?>


if(isset($_POST['submit'])) {

$to = "sales@cupargardencentre.co.uk";
$subject = "OnlineGardenCentre.uk.com Query";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Thank you for your comments to $to!";
mail($to, $subject, $body);
<?php echo($url); ?>

} else {

echo "Sorry, the e-mail function failed. Please try again or e-mail us directly at sales@cupargardencentre.co.uk";

}
?>



Thank you for your help!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You could use a meta refresh in the <head> of the page.

Code: Select all

<meta http-equiv="refresh" content="2;url=http://www.domain.tld/">
If you just want to display a link, then I have absolutely no clue why you even need to ask us how to.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

You can use the META refresh though it must within the head block.

Code: Select all

<meta http-equiv="refresh" content="5;url=http://example.com/index.php">
or using JavaScript to redirect. window.location = '';
Post Reply