<?php
	DEFINE("SITE_B_SHARED_KEY", "UIrewGOKjgdfkgjfdksjgfokishgrftyr4e$23");

	session_set_cookie_params(["samesite" => "Lax"]);
	session_start();
	session_regenerate_id(true);
	if(!isset($_SESSION['user'])){
		header("Location: index.php");
		exit;
	}
	
	$xsrftoken_dynamic = hash("sha256", openssl_random_pseudo_bytes(32));
	$xsrftoken_mixed = hash_hmac("sha256", $xsrftoken_dynamic, $_SESSION['xsrftoken']);
?><!DOCTYPE HTML>
<html lang="bg-BG">
<head>
	<title>Профил: <?=$_SESSION['user']?></title>
	<meta charset="utf-8" />
	<link rel="stylesheet" href="./includes/style.css" type="text/css" media="all" />
</head>
<body>
<div class="wrapper">
	<div class="header">
		<h1>Здравей <?=$_SESSION['user']?></h1>
	</div>
	<div class="search">
		<form action="search.php" method="GET">
			<input type="text" name="search" value='<?=htmlentities($_GET['search']??"", ENT_QUOTES, "UTF-8") ?>' />
			<input type="submit" value="Търси" />
		</form>
	</div>
	<div class="menu">
		<a href="securearea.php">Начало</a> |
		<a href="chat.php">Чат</a> |
		<a href="profile.php">Профил</a> |
		<a href="gallery.php">Галерия</a> |
		<a href="redir_to_B.php?user=<?=$_SESSION['user']?>&sign=<?=hash_hmac("sha256",$_SESSION['user'],SITE_B_SHARED_KEY)?>">Сайт Б</a> |
		<a href="logout.php?dt=<?=$xsrftoken_dynamic?>&mt=<?=$xsrftoken_mixed?>">Изход</a> |
	</div>
	<div class="sidebar">
<?php
	$link = mysqli_connect("localhost", "mainuser", "gfdagfda", "osup2020");
	$sql = "SELECT id, title FROM articles ORDER BY id";
	$result = mysqli_query($link, $sql);
	while($row = mysqli_fetch_assoc($result)){
		echo '<a href="articles.php?id='.$row['id'].'">'.$row['title'].'</a><br />';
	}
?>		
	</div>
	<div class="content">