Jump to content

Question regarding sessions and formdata


effkay

Recommended Posts

Hi.

 

I'm running a questionnaire on the web which consists of a basic html form, a php-script for sending the information, and a mysql database to store the information. To ensure that not everyone can get access to the questionnaire, I added a simple login-script which registers a new session. All subsequent pages after the login-page have "session_start; if !session_is_registered(username) { header(index.html); }. So thats working fine for now. However, I've been working on implementing serverside validation of the formdata and here's where the problem arise. Lets say someone entered a sql-command into a text-field, e.g. "SELECT * FROM $table" and submitted. This input would not validate with my current validation-script, since special characters like * and $ are banned. Ok... So the user now gets a html-page saying "Hey.. you used illegal characters. Go back and try again". When the user goes back, the questionnaire is blank, even though the user got it right on all other questions. Now I thought, since the user registers a new session when he logs in, that the form-data would be stored in that session, and that going back from the validation-error-page would display the questionnaire as the user tried to submit it. Has anyone got an idea as to what I should do?

 

I tested my current script in several browsers. Safari seems to be the only browser that stores the questionnaire, and displays it as it was prior to the error-page when going back.

 

Suggestions are appreciated!

-FK-

Link to comment
https://forums.phpfreaks.com/topic/76940-question-regarding-sessions-and-formdata/
Share on other sites

I think you would need to create a session for each of your form fields to accomplish what your wanting to do and then echo the session back into your input field.

 

<input type="text" name="FieldOne" value="<?php echo $_SESSION['FieldOneSessionName']; ?>">

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.