views:

140

answers:

4

Hello everyone,

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, which is the login.

How can i resolve this? Thanks

+1  A: 

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) ...

Rin
how do i add the parameter to a get array within the form? could you give an example in a form to be clear. Thanks
Using get parameters for storing session data is lame.
Leonid Shevtsov
Yyy ?;D why involve server and all session mechanism (`start_session();`, `$_SESSION ` array ? Moreover, tah variable won't be useful anytime later...
Rin
Your server is already "involved" by your script.
Leonid Shevtsov
+2  A: 

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"
  • 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.
Pascal MARTIN
Thanks for the useful info, what do you mean by adding variable on your two buttons? Do yu mean, in the form input to assign the information to any variable. Please could you clarify.Thanks
+2  A: 

Use a session variable, eg $_SESSION['clicked_button'] = $the_button.

Leonid Shevtsov
A: 

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 ;)

Les