Example input
<!DOCTYPE html>
<html lang="en">
<head>
<title>Steven's Gaming Gallery</title>
<link rel="stylesheet" href = "Style.css">
<link rel="stylesheet" href = "index.css">
</head>
<body>
<div class = "main">
<div class = "navbar">
<div class = "icon">
<h2 class = "logo">Steven's Gaming Gallery</h2>
</div>
<div class="welcome">
<h1>Welcome to Steven's Gaming Gallery</h1>
</div>
<?php
function session_is_valid() {
$db = new mysqli("localhost:3036", "root", "", "StevensGamingGallery");
// this looks at the cookies and checks if the session ID exists in our database
$validSession = mysqli_query($db, "select * from sessions where session_id = '" . addslashes($_COOKIE['sgg_session']) . "' and has_logged_out = 'n'");
if (mysqli_num_rows($validSession) == 1) {
$thisSession = mysqli_fetch_assoc($validSession);
// check if no older than 2 hours
if ($thisSession['when_logged_in'] > time()-7200) {
// session valid
return true;
} else {
return false;
// die("sorry your session has expired. please log in again");
}
} else {
return false;
// die("session does not exist");
}
}
if (session_is_valid()) { ?>
<div class = "menu">
<u1>
<li><a href = "Action.html">Action</a></li>
<li><a href = "Race.html">Race</a></li>
<li><a href = "About.html">About</a></li>
<li><a href = "Cliker.html">Cliker</a></li>
<li><a href = "Arcade.html">Arcade</a></li>
</u1>
</div>
<div class="search">
<input class = "srch" type="search" name="" placeholder="Search Game">
<a href = "#"> <button class="btn">Search</button> </a>
</div>
<div class="logout">
<a href="logout.php">Log out</a>
</div>
<?php } else { ?>
<div class = "login">
<h2>
<li><a href = "login.html">Login</a></li>
</h2>
</div>
<div class = "Sign-up">
<h2>
<li><a href = "Sign-up.html">Sign-up</a></li>
</h2>
</div>
<?php } ?>
</div>
</div>
Example output
Sure, I can help you with that.
This section of code appears to be a web page written in HTML and PHP. The HTML code contains a page title, two links to cascading style sheets (CSS), and a body section. Within the body section, there is a div element with the class "main" that contains two other div elements, one with the class "navbar" and the other with the class "welcome". The "navbar" div element contains an icon element and an unordered list with five links to different pages of the website. The "welcome" div element displays a header welcoming the user to the website.
The PHP code checks if the user has a valid session by accessing the database using the mysqli extension, which connects to the local host database with the username "root" and password "" (empty string). The session_is_valid function checks if the session ID exists in the database and if the user has logged out or not. If the session ID exists and the user has not logged out, it checks if the session is not older than two hours. If the session is valid, it displays a menu with links to different pages, a search bar, and a logout button. If the session is invalid, it displays a login and sign-up button.
There don't appear to be any errors or inefficiencies in the code, although it's worth noting that it assumes a local database and may not be secure against SQL injection attacks.
One improvement that could be made is to use prepared statements to prevent SQL injection attacks. Additionally, the code could be made more modular and reusable by separating out the database connection and session checking into separate functions that can be used throughout the website. Finally, adding comments to the code can make it more readable and easier to maintain.