Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. <?php
  2. function saveBasket(){
  3.     global $basket;
  4. $basket = base64_encode(serialize($basket));
  5. setcookie('basket', $basket, 0x7FFFFFFF);
  6. }
  7. function basketInit(){
  8.     global $basket, $count;
  9. if(!isset($_COOKIE['basket'])){
  10. $basket = ['orderid' => uniqid()];
  11. saveBasket();
  12. }else{
  13. $basket = unserialize(base64_decode($_COOKIE['basket']));
  14. $count = count($basket) - 1;
  15. }
  16. }
  17. function add2Basket($id){
  18.     global $basket;
  19.     $basket[$id] = 1;
  20.     saveBasket();
  21.   }
  22.  
  23.  
  24.  $id = $_GET ["id"];
  25. if ($id){
  26.     add2Basket ($id);
  27.     header("Location: catalog.php");
  28.     exit;
  29.     }
  30.  ?>
  31. <p>Товаров в <a href="basket.php">корзине</a>: <?=$count?></p>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement