SHARE
TWEET

Untitled

a guest Jan 24th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top