EvilZone

Programming and Scripting => Web Oriented Coding => : m0l0ko December 21, 2012, 05:26:41 AM

: Passing variables from javascript to PHP via cookies
: m0l0ko December 21, 2012, 05:26:41 AM
When I was trying to find out if you could pass variables from javascript to PHP in the past, I came to the conclusion that you can't based on what other people were saying. You can create cookies with javascript then read them with PHP. Are there any major downsides to doing this (besides the fact that not everyone enables cookies)?
: Re: Passing variables from javascript to PHP via cookies
: p_2001 December 21, 2012, 05:44:17 AM
Cookies can be read by anyone.. Means that security is compromised.
: Re: Passing variables from javascript to PHP via cookies
: ande December 21, 2012, 12:57:03 PM
You can pass it as a GET or POST argument as well.

:
window.location = 'index.php?variable='+var;
: Re: Passing variables from javascript to PHP via cookies
: m0l0ko December 26, 2012, 03:47:13 AM
You can pass it as a GET or POST argument as well.

:
window.location = 'index.php?variable='+var;

Yeah the main downside there is that you have to update the page. Plus, if your variables are large strings, passing them through URL variables would be very messy looking.
: Re: Passing variables from javascript to PHP via cookies
: Stackprotector December 26, 2012, 09:56:07 AM
Yeah the main downside there is that you have to update the page. Plus, if your variables are large strings, passing them through URL variables would be very messy looking.
lol, Because of this Ajax is invented http://en.wikipedia.org/wiki/Ajax_(programming) . I use the ajax jquery function and send json data to my php's json controller (wich is actually an switch loop) . :D goodluck
: Re: Passing variables from javascript to PHP via cookies
: ande December 27, 2012, 05:40:46 PM
Yeah the main downside there is that you have to update the page. Plus, if your variables are large strings, passing them through URL variables would be very messy looking.

Javascript can sent GET/POST data without reloading the page using XMLHttpRequest. (pretty much what Factionwars said)