View Full Version : passing values between javascript and PHP using cookies

12-24-2003, 12:23 AM

I know there are issues with passing values obtained using javascript then wanting to use them in PHP, so heres where I'm having a problem.

I have vars created in Javascript so have created a cookie containing them, loads new php page and want to load the cookie values back to php so I can write them to MYSQL after verifying more data from the user.

Is this possible, Is this even a workable method, are there better ways to do this, can this even be achieved.

I aam extremely new to this kind of thing so any assistance pointers or even full solutions would be appreciated.

I am using Phorm (form tools) and get the initial javescript vars in my first form but dont want to use them until I have verified all the input from the user contained in aditional forms.

Many thanks:confused:

12-24-2003, 05:00 PM
yes you can use cookies , I would suggest sessions if only because they cater for users regardless of whether they have cookies enbaled or not (they are also simply easier to use)...

in your form processing script ..

session_start() ;

//validate your _POSTed variables etc
//then add to the session
$_SESSION['variable_name'] = $_POST['variable_name'] ;

then whenever you want to use them ..

var variable_name = <?=$_SESSION['variable_name'] ;?>;

12-24-2003, 05:04 PM
Thanks Firepages

Will see what i can do using sessions, will let you know how i get on:)