function saveBasket global basket basket base64_encode serialize baske

 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
function saveBasket(){
global $basket;
$basket = base64_encode(serialize($basket));
setcookie('basket', $basket, 0x7FFFFFFF);
}
function basketInit(){
global $basket, $count;
if(!isset($_COOKIE['basket'])){
$basket = array('orderid' => uniqid());
saveBasket();
}else{
$basket = unserialize(base64_decode($_COOKIE['basket']));
$count = count($basket) - 1;
}
}
basketInit();
function add2Basket($id){
global $basket;
$basket[$id] = 1;
saveBasket();
}
if(isset($_GET['id'])){
$id = $_GET['id'];
add2Basket($id);
header("Location: catalog.php");
}