This forum is in archive mode. You will not be able to post new content.

Author Topic: Passing variables from javascript to PHP via cookies  (Read 4107 times)

0 Members and 1 Guest are viewing this topic.

Offline m0l0ko

  • Peasant
  • *
  • Posts: 129
  • Cookies: -4
    • View Profile
Passing variables from javascript to PHP via cookies
« on: 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)?

Offline p_2001

  • Royal Highness
  • ****
  • Posts: 684
  • Cookies: -64
    • View Profile
Re: Passing variables from javascript to PHP via cookies
« Reply #1 on: December 21, 2012, 05:44:17 AM »
Cookies can be read by anyone.. Means that security is compromised.
"Always have a plan"

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Passing variables from javascript to PHP via cookies
« Reply #2 on: December 21, 2012, 12:57:03 PM »
You can pass it as a GET or POST argument as well.

Code: [Select]
window.location = 'index.php?variable='+var;
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline m0l0ko

  • Peasant
  • *
  • Posts: 129
  • Cookies: -4
    • View Profile
Re: Passing variables from javascript to PHP via cookies
« Reply #3 on: December 26, 2012, 03:47:13 AM »
You can pass it as a GET or POST argument as well.

Code: [Select]
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.

Offline Stackprotector

  • Administrator
  • Titan
  • *
  • Posts: 2515
  • Cookies: 205
    • View Profile
Re: Passing variables from javascript to PHP via cookies
« Reply #4 on: 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
~Factionwars

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: Passing variables from javascript to PHP via cookies
« Reply #5 on: 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)
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.