Piotr Ciszewski
Piotr Ciszewski

Reputation: 1791

Include URL in PHP form

I use the same form on multiple pages within one website. Each page has a different category, so when someone send a question I want to know on which page the form was used. How to include the URL of the page on which the form was used? I want to modify just .php file, not all files on all pages.

Here is the code

    <?php

      $addressto = "[email protected]";
      $subject = "Message from the website x.co.uk";
      $content = "First Name: ".$_POST['first-name']."\n"
                   ."Last Name: ".$_POST['last-name']."\n"
                   ."Company: ".$_POST['company']."\n"
                   ."Email: ".$_POST['email']."\n"      
                   ."Tel.: ".$_POST['phone']."\n"     
                   ."Event Date: ".$_POST['date']."\n"     
                   ."Location: ".$_POST['location']."\n"     
                   ."No of guests: ".$_POST['guests']."\n"     
                   ."Message: ".$_POST['message']."\n"
                   ."Referer: ".$_POST['findus']."\n";

        $email = $_POST['email'];
        if (mail($addressto, $subject, $content, 'From: <' . $email . '>')) {
            header("Location: message-sent.html");
        }

    ?>

Thank you

Upvotes: 1

Views: 91

Answers (2)

Lucisu
Lucisu

Reputation: 23

Well, if you want to change only the included .phṕ file, without adding anything to all pages, you can use this code (described here):

$actual_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

NOTE: It is important to note that, as described in the link, a user can change the variables "HTTP_HOST" and "REQUEST_URI".

Upvotes: 0

Geme
Geme

Reputation: 447

You can use a hidden field with value of current url

Upvotes: 1

Related Questions