473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

cookies and session variables

Hello,
I need to save values typed into forms across several scripts, before
the user actually 'submits' the form to update the mysql db.

I have been exploring ways to do this, and looking for some guidance as
to whether to use
cookies or PHP session variables.

Should my use of either be conservative due to performance reasons?
What are the advantages of either?

To briefly describe what I am trying to do:
I have 3 forms : formA, formB and formC
each has about 15 entry fields (from the same mysql table).
formA has fieldA1, fieldA2, etc
formB has fieldB1, fieldB2, etc
formC has fieldC1, fieldC2, etc

The user can navigate from formA to formB, etc with a button click.
Right now, I am populating each form from the mysql db value. But I
need to save values typed in while the user navigates from page to
page. Eventually, the user submits and I update the db from all forms.
The easiest way for me to incorporate this into my existing logic is
to, before going into formA, set a cookie (or session variable) for
each field. If they go to formA and change a value, reset the cookie
(I am doing this with an onblur call to javascript function.) Seems
inefficient for me to set a cookie for every field...they may only
change 1 field...or none.
But I am having trouble grasping any other way to do it....Thus, my
question about efficiencies, performance, etc.
Thanks for any advice!

Nov 24 '05 #1
7 2350
Ian
Japhy wrote:
Hello,
I need to save values typed into forms across several scripts, before
the user actually 'submits' the form to update the mysql db.

I have been exploring ways to do this, and looking for some guidance as
to whether to use
cookies or PHP session variables.

I'd use sessions for this, otherwise the user's data is being send back
and forwards in each HTTP request and response. Even with a secure
connection, you may also end up with potentially sensitive data left in
the plain test browser cookie file.

I keep an array of form inputs in my session and import them into each
form as it is generated, so common fields between forms get filled in
when the user moves on to a new form.

Ian
Nov 24 '05 #2
Thanks for the reply. What you say makes sense. Right now I am using
code in the <input for each field :
onblur="javascript:set_cookie('mycookie',document. forms0].FieldA.value)"

(set_cookie being a javascript function :
// set_cookie(name, value [,expires, path, domain, secure])
// Set cookie value.
function set_cookie (name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "")
+
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
I found on the internet.
Can I set session variables likewise...in a javascript function? I
have tried to find the right syntax, and so far no luck. My other idea
was to POST when they page from 1 page to another to collect the
values, but I am already POSTING on the form to handle the validation
and input of data.
Would you suggest :
1) running some kind of JS function onblur to set the session
variables?...like I'm doing now with cookies.
2) putting some kind of logic in my form handling script to distinguish
if they are paging from 1 to another page, or 'submitting' the form?
3) something entirely different
Thanks again!

Nov 24 '05 #3
Ian
Japhy wrote:
Thanks for the reply. What you say makes sense. Right now I am using
code in the <input for each field :
onblur="javascript:set_cookie('mycookie',document. forms0].FieldA.value)"

Can I set session variables likewise...in a javascript function?
Sessions are purely server side.

Use session_start() to create one and the $_SESSION super global to
store your data (which can be harvested from $_POST) between pages. No
client side code is required.

Would you suggest :
1) running some kind of JS function onblur to set the session
variables?...like I'm doing now with cookies. Nope.
2) putting some kind of logic in my form handling script to distinguish
if they are paging from 1 to another page, or 'submitting' the form? Yes. You can use the value of your submit button for this.
3) something entirely different

Maybe....

Ian
Nov 24 '05 #4
Thanks for your advice. I'll look this up, but in case I can't find
it....How do I get the value of the submit
button in my form handling script. IE : FormA.php, when submitted,
posts to FormHandler.php (this is where I do my
validation and DB insert or set.
TIA

Nov 25 '05 #5
Hello, I think I got it $_POST[submit]...thanks again

Nov 25 '05 #6
Ian
Japhy wrote:
Thanks for your advice. I'll look this up, but in case I can't find
it....How do I get the value of the submit
button in my form handling script. IE : FormA.php, when submitted,
posts to FormHandler.php (this is where I do my
validation and DB insert or set.
TIA

$_POST[<button name>] = <button value>

Where name and value are attributes of the button input.

Ian
Nov 25 '05 #7
Thanks again, Ian, for your advice.
This seems like it is going to solve
my problem (easier than I thought, too)
Couldn't have done it without you!
Much appreciated.

Nov 25 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kublai khan | last post by:
I am coming from (an elementary-level) javascript background. I set cookiesin select pages to see where the users are coming from and where they are going. It works quite nicely except that I'd...
20
by: Brian Burgess | last post by:
Hi all, Anyone know if this is possible? If so, on which page would the cookie be? .. On the page calling a function defined in the include file? thanks in advance.. -BB
2
by: Amit D.Shinde | last post by:
Hello Experts.. I need some help regarding cookies and session objects and also global.asa file I am creating one cookie when a user logs in on my website. The cookie stores the login name of...
9
by: | last post by:
Is it possible for a user to enable permanent cookies but disable session cookies.....this seems like a contradition yet this is what I appear to be reading in online articles?
2
by: What-a-Tool | last post by:
I am using a couple of session variables in my site. From what I can figure out, session information is stored on the users computer in a cookie - If the user has cookies disabled, do session...
3
by: Galina Grechka | last post by:
Hi, I have a really bad problem with ASP.net application. It seemed fine until it was tested in multisession environment. When 2 users access the same aspx page at the same time sometimes the...
6
by: Paul | last post by:
Here is a question that should get everyone going. I have an ecommerce site where I need to pass the order_id to every page. So which method is the best practice to pass this variable between...
5
by: jheines | last post by:
I am trying to explain how cookies and sessions work in a class I teach, but I have hit a wall when it comes to the interaction between cookies and the state of the privacy settings in Internet...
3
by: damezumari | last post by:
To find out were session variables are stored I included this instruction in my program: echo ini_get("session.save_path"); The reply was /home/7604/data/tmp which is a folder on my server. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.