Reputation: 723
Is there an easy way to find out the source of a post variable in PHP?
<form method="post" action="test.php">
<input name="myusername"type="text">
<input name="mypassword" type="password">
<input type="submit">
</form>
<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.
Upvotes: 3
Views: 821
Reputation: 17457
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 input
for a submit button
. This way you can pass a value with it, retain the button's label, and test for that inside your test.php
page:
<button name="submit" type="submit" value="form1">Submit</button>
In your PHP file you would then test:
if( $_POST['submit'] == "form1" )
// do something
Upvotes: 8