[PHP] variabele in cookie

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Sabi
  • Registratie: Mei 2002
  • Laatst online: 08-01-2022
Ik heb in een cookie variabele variabele staan :)
In het cookie ziet dat er zo uit:

test_01
01

test_03
03

Etc.

Nu wil ik graag checken of er een variabele in de cookie is:
PHP:
1
2
3
4
5
foreach ($whahoee as $key => $val) { 

  $check_freq = "$$test_".$val; 

  if ($val == $stored_window_no or $val == $check_freq)

Als ik in $check_freq = $test_02 zet werkt het prima, maar het deel 02 is variabel namelijk $val. Dus zo zou het niet voor alle variabelen werken.

Acties:
  • 0 Henk 'm!

  • Janoz
  • Registratie: Oktober 2000
  • Laatst online: 16-09 09:15

Janoz

Moderator Devschuur®

!litemod

Het lijkt me handig om even enkele dingen over arrays en over de $_COOKIE variabel door te nemen.

Ken Thompson's famous line from V6 UNIX is equaly applicable to this post:
'You are not expected to understand this'


Acties:
  • 0 Henk 'm!

  • Sabi
  • Registratie: Mei 2002
  • Laatst online: 08-01-2022
tnx.
Ik heb het zo opgelost:

$check_freq = $_COOKIE["test_$val"];