Am I using a PHP session correctly to save data between forms?

Just a quick question.

I have a form that captures a bit of data, validates it and then sends it to another page on the same site. I use header () to redirect if there are no errors, but obviously the data is not sent in the message.

Would it be right to use a session to save data between two pages?

Thanks guys.

+4
source share
5 answers

If you only need the data on the second page, and if the data is not sensitive, you can also pass the data to header ().

$url = "www.example.com?variable=value&id=something"; Ie header('Location: $url'); 
+3
source

These flash messages are great and are a good way to prevent the user from reloading the page and re-submitting the form if you are worried about it. I would remind you to turn off session vars after displaying a message.

0
source

Yes, this is the right approach.

However, depending on the situation, there are other alternatives, such as hidden variables, iframes, etc. If you could explain the whole situation, depending on the nature of the data, I can provide you with a very accurate answer.

0
source

Data can be stored on the server side (session) or on the client side (Cookie). Which method you choose depends on the type of data and security concerns.

You can also embed published data via PHP directly into a new form without saving, but this will not work if you redirect through the header

0
source

Yes, you can do it, but to be even safer, add this to db with an extra DUMMY field or something like that. by this, if you need to refuse, you can drop the dummy record. But you must have a time stamp so as not to delete those entries that have recently been added and are in the process.

you can also create a cron job to delete a table

0
source

All Articles