Redirect Using PHP - Multiple sites feeding one form

I have a number of sites with the same contact page, and I made a PHP form for each site that sends me an email when someone fills out the contact form. The php form then redirects the person to a ‘goodbye’ page.

For example, here are two of my contact forms:
http://rentlakegeorge.com/lake_george_contact.htm
http://schroonlakerentals.com/schroon_lake_contact.htm

Each of the above pages has a PHP form that automatically sends me an email. The PHP form then re-directs the person to a goodbye page:
http://www.rentlakegeorge.com/contact_php.php
http://www.schroonlakerentals.com/contact_php.php

I have many other sites with the same setup. Below is a copy of my standard PHP form. The question is this: instead of making a new PHP form every time I start a new site, I’d like to keep just one PHP form for all my sites. Here is the problem: As you see below, I usually just redirect to ‘contact-thankyou.htm’, which works fine because the PHP form is sitting within the domain. However, if I setup a PHP form on MYSITE.com and have the rentlakegeorge.com and schroonlakerentals.com contact forms use that PHP form, how do I re-direct them back from MYSITE.com to the rental site??? I think the ‘$Website’ value should be used in the $redirect_to formula but I can’t figure out how to do it.

Thanks in advance for any advice.

MY PHP FORM AS IT IS:
[php]

<? $redirect_to = 'contact-thankyou.htm'; $recipient = '[email protected]'; $Website = $_REQUEST['website']; $Contact_FullName = $_REQUEST['Contact_FullName']; $Contact_Email = $_REQUEST['Contact_Email']; $Contact_WorkPhone = $_REQUEST['Contact_DayPhone']; $Contact_HomePhone = $_REQUEST['Contact_NightPhone']; $Comments = $_REQUEST['Comments']; $message = "The following is a $Website contact form submission: Name: $Contact_FullName Email: $Contact_Email Day Phone: $Contact_DayPhone Night Phone: $Contact_NightPhone Questions or comments: $Comments "; mail ($recipient, 'Contact Form', $message, "From: $Contact_Emailrn"); header ("Location: $redirect_to"); ?>

[/php]

– MOD EDIT - ADDED PHP TAGS FOR EASIER READING

The easiest thing I can see here is to just put the whole URL of the location where the file is. Add the http:// and the URL and it should work. If you are passing variables, I believe if you set up a $_SESSION variable by calling session_start(); at the top of all of your pages that use this script then the information should get passed. I don’t know if it would or not, I never had to deal with multiple websites.

Check at http://www.php.net for $_SERVER[‘REQUEST_URI’] or $_SERVER[‘HTTP_REFERER’];

You should be able to pull which site they are coming from and you should be able use that in the redirect.

Hope that helps!

Thanks for the suggestions! I tried the $_SERVER functions but they are out of my skill range. I ended up just changing the ‘header’ function.

Originally it was:
header (“Location: $redirect_to”);

I changed it to
header (“Location: http://www.$Website/contact-thankyou.htm”);

Again, thanks for your help.

Sponsor our Newsletter | Privacy Policy | Terms of Service