-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.php
110 lines (102 loc) · 2.18 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
if(isset($_COOKIE['idtowary']))
{
echo '<br>id ';
var_dump($_COOKIE['idtowary']);
}
if(isset($_COOKIE['ilosci']))
{
echo '<br>ilosci ';
var_dump($_COOKIE['ilosci']);
}
*/
/*
$IdTowar = 1;
$ilosc = 2;
if(!isset($_COOKIE['test']))
{
$ids = array();
$ids[] = $IdTowar;
$dane = json_encode($ids);
setcookie('test', $dane,time()+60*60*24*30,'/');
$_COOKIE['test'] = $dane;
}
else
{
$cookie = $_COOKIE['test'];
$cookie = stripslashes($cookie);
$ids = json_decode($cookie, true);
$ids[] = $IdTowar;
$dane = json_encode($ids);
setcookie('test', $dane,time()+60*60*24*30,'/');
$_COOKIE['test'] = $dane;
}
if(!isset($_COOKIE['test2']))
{
$quantity = array();
$quantity[] = $ilosc;
$dane = json_encode($quantity);
setcookie('test2', $dane,time()+60*60*24*30,'/');
$_COOKIE['test2'] = $dane;
}
else
{
$cookie = $_COOKIE['test2'];
$cookie = stripslashes($cookie);
$quantity = json_decode($cookie, true);
$quantity[] = $ilosc;
$dane = json_encode($quantity);
setcookie('test2', $dane,time()+60*60*24*30,'/');
$_COOKIE['test2'] = $dane;
}
//var_dump($_COOKIE['test']);
//var_dump($_COOKIE['test2']);
*/
$jakiesid=3;
var_dump($_COOKIE['idtowary']);
echo '<br>';
var_dump($_COOKIE['ilosci']);
echo '<br>';
$cookie2 = $_COOKIE['idtowary'];
$cookie2 = stripslashes($cookie2);
$ids = json_decode($cookie2, true);
if(($k = array_search($jakiesid, $ids)) === false)
{
// echo 'nie ma';
}
else
{
//echo 'jest';
$indeks = array_search($jakiesid, $ids);
}
$cookie = $_COOKIE['ilosci'];
$cookie = stripslashes($cookie);
$quantity = json_decode($cookie, true);
if(($k = array_search($jakiesid, $ids)) === false){}
else
{
$quantity[$indeks]=2;
}
$dane = json_encode($quantity);
setcookie('ilosci', $dane,time()+60*60*24*30,'/');
$_COOKIE['ilosci'] = $dane;
echo 'ewentualna zmiana';
echo '<br>';
var_dump($_COOKIE['ilosci']);
/*
$cookie = $_COOKIE['idtowary'];
$cookie = stripslashes($cookie);
$ids = json_decode($cookie, true);
$cookie = $_COOKIE['ilosci'];
$cookie = stripslashes($cookie);
$quantity = json_decode($cookie, true);
foreach (array_combine($ids, $quantity) as $code => $name)
{
echo 'id: '.$code;
echo ',';
echo 'ilosc: '.$name;
echo '<br>';
}
*/
?>