The above pattern is supposed to be used as a workaround to avoid form resubmission, I.E
If some data is entered into a form on page A, posted to page B and validated + saved on page B. Then if the page is refreshed, the browser will show an error page as well as a prompt to let you know you are about to send all your data again (post it). This is bad, especially in systems which allow a bank transaction to be made; whereby with each refresh the same data is reposted and the request is remade, and the money is rewithdrawn.

To avoid it, the aforementioned method states;
1) user fills form on page A and presses submit
2) post request is sent to page B which in turn processes the data, if all validates the data is sent using the GET request
3) to page C

The problem I am having is how do you redirect from page B to page C using the GET request as page B is just a process & redirect page without a form. I would like to send the userid after it has been validated. Using a GET method to send this will allow for the url to be unique which can then be shared across users I attempt to have on my website.

I'm not able to do the redirect with GET parameters the following way;

    header('Location: pageB.php?q=$id');

The other methods I have thought of could be to put a hidden form on page B, and redirect to page C by submitting page B with javascript if validation returns true.

Another way I suppose would be to have an <a href='#' /> link which is clicked upon using Jquery if validation succeeds.

But these two use the methods which are aided by javascript which I believe may be unsafe (though I'd be happy if someone could reconfirm/refute this), and if someone has javascript disabled they wont be able to traverse to the next page.

If there are any other options available for me I'd really like to hear some!

Recommended Answers

All 7 Replies

Your first method sounds like a good idea and I think it suppose to read:

header(Location: pageC.php?q=$id');

Since pageC is the target.

The page name isn't the concern here, appending parameters within the header() function in php does not work.

Member Avatar for diafol

For parsing variables, you need to use double quotes:

header("Location: pageB.php?q=$id");

I also saw that 'solution' online somewhere, but that doesn't work either. Seems like you cannot append anything with the header() function at all. The next page simply gives the error;
Notice: Undefined index: q in path on line 4

Ahhhh! sorry about that, you helped me discover some other problem that was preventing this from happening in my code so thank you very much for that!

Member Avatar for diafol

Ok, solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.