$url = "https://st.kp.yandex.net/images/film_iphone/iphone360_1152188.jpg";
$path = 'posters/' . time() . ".jpg";
$ch = curl_init($url);
$fp = fopen($path, 'wb');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
if (isset($_POST['username']) and isset ($_POST['password'])){
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$role = $_POST['role'];
$query = "SELECT
`u`.`id`
FROM `users` AS `u`
WHERE
`u`.`username`='" . mysqli_real_escape_string($connection, $_POST['username']) . "'
OR
`u`.`email`='" . mysqli_real_escape_string($connection, $_POST['email']) . "'
";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) == 0) {
$query = "INSERT INTO `users`
(
`username`,
`email`,
`password`,
`role`
)
VALUES (
'" . mysqli_real_escape_string($connection, $_POST['username']) . "',
'" . mysqli_real_escape_string($connection, $_POST['email']) . "'
'" . mysqli_real_escape_string($connection, $_POST['password']) . "'
'user'
)";
$result = mysqli_query($connection, $query);
if ($result) {
header('Location: index.html');
$smsg = "Регистрация прошла успешно";
}
else {
$fsmsg = "Ошибка";
}
}
else {
$fsmsg = "Повтор";
}
}
$_SESSION['total']['count'] = 0;
$_SESSION['total']['summ'] = 0;
$id = $_POST['id'];
if($_SESSION['cart']) {
if($_SESSION['cart'][$id]) {
$_SESSION['cart'][$id]++;
}
else {
$_SESSION['cart'][$id] = 1;
}
foreach($_SESSION['cart'] as $key => $val) {
$_SESSION['incart'][$key] = pageData("SELECT title, price, img FROM records WHERE id=".$key);
$_SESSION['incart'][$key]['count'] = $val;
$sum = $_SESSION['incart'][$key]['price'] * $_SESSION['incart'][$key]['count'];
$_SESSION['total']['count'] += $_SESSION['incart'][$key]['count'];
$_SESSION['total']['summ'] += $sum;
}
print_r($_SESSION['incart']);
print_r($_SESSION['total']);
}
else {
$_SESSION['cart'][$id] = 1;
}