Fountain Enabler
Fountain Enabler

Reputation: 27

How to reference form URL in new PHP file?

I want to send POST variables from a form to be played around with in a PHP file and then have the PHP file redirect the user back to the original site the form was submitted. How could I reference the form's original URL from the PHP file so that I could use the same PHP file for multiple websites?

Upvotes: 0

Views: 44

Answers (1)

Angry 84
Angry 84

Reputation: 2995

You would want to use something like

$_SERVER['HTTP_REFERER']

But this is controlled by the client side / browser.. So should not be trusted as such. A more preferred method for myself is to either include the url as a hidden input or have something like sessions store the last page.

<form method="POST" action="someurl.php">
    <input type='hidden' name='sent_from' value='<?php echo $_SERVER['PHP_SELF']; ?>' />
    <!-- Normal form data from this point -->
</form>

someurl.php

<?php
    echo $_POST['sent_from']; // This will contain the page that posted to this file.
?>

Upvotes: 1

Related Questions