0

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?

1 Answer 1

1

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.
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.