Is there an easy way to find out the source of a post variable in PHP?
Form on example.com/formone.php
<form method="post" action="test.php">
<input name="myusername"type="text">
<input name="mypassword" type="password">
<input type="submit">
</form>
Form on example.com/formtwo.php
<form method="post" action="test.php">
<input name="myusername"type="text">
<input name="mypassword" type="password">
<input type="submit">
</form>
I understand that I could use a hidden input, but I was wondering if PHP had a method to test the source of the POST.
While you could potentially use the HTTP_REFERER server variable, it is not very reliable. Your best bet would be to use a hidden field.
Another alternative would be to switch out your submit
inputfor a submitbutton. This way you can pass a value with it, retain the button’s label, and test for that inside yourtest.phppage:In your PHP file you would then test: