Referer in php-
What is the best method of doing the following: I have Page A with 2 buttons(for different things) which both take you to a login page(Page 3), When login details are filled in Page 3, the page that handles the data is page 4. I want page 4 to show things depending on which button was clicked in page a. I have read upon http referer, but i believe if i place a referer in Page 4, it will show the previous page that i am coming from, whic开发者_C百科h is the login.
How can i resolve this? Thanks
The referer is not always sent by browsers, and can be faked (and, in this case, as both buttons are on the same page, it would be kind of useless) ; so, you should not depend on it being set nor correct.
In this situation, a possible solution would be to :
- on page A, add some variable on your two buttons
- like "
page_login.php?button=1
" - and "
page_login.php?button=2
"
- like "
- page login will receive that variable (ie,
$_GET['button']
), and store it in a hidden field of the form - page 4 will, in turn, then receive that variable ; and you can use it to know which button was first used.
Use a session variable, eg $_SESSION['clicked_button'] = $the_button
.
http-refferer is not the best solution to do this. Simplest way is add some parametr to GET array, for example ?clicked_button=2
Http-refferer could be off. Moreover, referer will be display same url for that buttons (both of them are in ONE page)
EDIT on request:
You could do it without form,
<button id="button1" onClick = "javascript:location = "page3.php?clicked_button=1"; />
and in page3.php
just read value in $_GET['clicked_button']
:
if($_GET['clicked_button'] == 1) ...
Remember to have a default in any case if those variables do not exist, ie user interferes with your form... but you should be using methods to prevent that anyways ;)
精彩评论