php session_start include common_func php if isset _GET ajax and isset

 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
<?php
session_start();
include('common_func.php');
if ( (isset($_GET["ajax"])) and (isset($_POST["id"])) and (isset($_POST["price"])) and (isset($_POST["action"])) )
{
if (isset($_SESSION["cart"])){
$cart=$_SESSION["cart"]; }
$index=search_by_id($cart,$_POST["id"]);
switch ($_POST["action"])
{
case "add":
if ( $index<0 )
{
$cart[]=array("id"=>intval($_POST["id"]),"price"=>intval($_POST["price"]),"count"=>1);
} elseif ($index>=0)
{
$cart[$index]["count"]+=1;
}
break;
case "delete":
if ( $index>=0 )
{
if ($cart[$index]["count"]>1)
{
$cart[$index]["count"]-=1;
} else
{
unset($cart[$index]);
//$cart=array_diff($cart,$cart[$index]);
}
}
break;
case "erase":
unset($cart[$index]);
break;
}
$_SESSION["cart"]=$cart;
} elseif ( (isset($_GET["ajax"])) and ($_POST["action"]=="erase") )
{
if (isset($_SESSION["cart"]))
{
$_SESSION["cart"]=null;
}
}
?>