I’m currently working on a personal project where I create a cool website (It was not cool). I tried asking AI for mostly all the stuff I need on PHP Project. I have been pretty good at HTML and CSS.
The issue is because the $_SESSION is not remembering anything! When I tried to use var_dump($_SESSION), it gave me array(0) { }. I asked AI so many times, I was starting to think the AI Control was gonna explode. Here is the code:
index.php:
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<a href="contact.html">Contact</a>
<a href="services.html">Services</a>
// Improved logic for logout link with actual value check
if (isset($_SESSION['name']) && isset($_SESSION['password']) && !empty($_SESSION['name']) && !empty($_SESSION['password'])) {
echo '<a href="/logout.php" class="login-link">Log Out</a>';
<a href="/form/signUp.php" class="login-link">Sign Up</a>
<a href="/form/logIn.php" class="login-link">Log In</a>
if (isset($_SESSION['name']) && !empty($_SESSION['name'])) {
<h1>Welcome, " . $_SESSION["name"] . "!</h1>
if (!isset($_SESSION['loggedin']) || !$_SESSION['loggedin']) {
// Redirect to login if not logged in
header('Location: /form/signUp.html');
Hello! I assume you've followed this program for its activities and goals. If not, and you're just visiting, feel free to explore!
This website is intentionally exposed within a specific network. Here are some additional details about the website and its purpose (replace with your actual content).
<p>**Important Security Reminder:** Always be cautious when accessing exposed network websites. Take necessary precautions to protect your information.</p>
<small>This is copyrighted by the laws of physics ©. It must not be pirated or copied in any way possible. Anyways.. pls dont copy this bc im gona gst sued!1!1</small>
<code><?php
session_start();
var_dump($_SESSION);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="first">
<h1>Home Page</h1>
<br>
<nav class="nav">
<a href="contact.html">Contact</a>
<a href="services.html">Services</a>
<?php
// Improved logic for logout link with actual value check
if (isset($_SESSION['name']) && isset($_SESSION['password']) && !empty($_SESSION['name']) && !empty($_SESSION['password'])) {
echo '<a href="/logout.php" class="login-link">Log Out</a>';
} else {
echo '
<a href="/form/signUp.php" class="login-link">Sign Up</a>
<a href="/form/logIn.php" class="login-link">Log In</a>
';
}
?>
</nav>
</header>
<br>
<main class="center">
<header>
<?php
if (isset($_SESSION['name']) && !empty($_SESSION['name'])) {
echo "
<h1>Welcome, " . $_SESSION["name"] . "!</h1>
";
} else {
echo "
<h1>Welcome, Guest!</h1>
";
}
if (!isset($_SESSION['loggedin']) || !$_SESSION['loggedin']) {
// Redirect to login if not logged in
header('Location: /form/signUp.html');
exit();
}
?>
</header>
<br>
<main>
<h3>
Hello! I assume you've followed this program for its activities and goals. If not, and you're just visiting, feel free to explore!
This website is intentionally exposed within a specific network. Here are some additional details about the website and its purpose (replace with your actual content).
<p>**Important Security Reminder:** Always be cautious when accessing exposed network websites. Take necessary precautions to protect your information.</p>
</h3>
</main>
</main>
<footer class="last">
<small>This is copyrighted by the laws of physics ©. It must not be pirated or copied in any way possible. Anyways.. pls dont copy this bc im gona gst sued!1!1</small>
</footer>
</body>
</html>
</code>
<?php
session_start();
var_dump($_SESSION);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="first">
<h1>Home Page</h1>
<br>
<nav class="nav">
<a href="contact.html">Contact</a>
<a href="services.html">Services</a>
<?php
// Improved logic for logout link with actual value check
if (isset($_SESSION['name']) && isset($_SESSION['password']) && !empty($_SESSION['name']) && !empty($_SESSION['password'])) {
echo '<a href="/logout.php" class="login-link">Log Out</a>';
} else {
echo '
<a href="/form/signUp.php" class="login-link">Sign Up</a>
<a href="/form/logIn.php" class="login-link">Log In</a>
';
}
?>
</nav>
</header>
<br>
<main class="center">
<header>
<?php
if (isset($_SESSION['name']) && !empty($_SESSION['name'])) {
echo "
<h1>Welcome, " . $_SESSION["name"] . "!</h1>
";
} else {
echo "
<h1>Welcome, Guest!</h1>
";
}
if (!isset($_SESSION['loggedin']) || !$_SESSION['loggedin']) {
// Redirect to login if not logged in
header('Location: /form/signUp.html');
exit();
}
?>
</header>
<br>
<main>
<h3>
Hello! I assume you've followed this program for its activities and goals. If not, and you're just visiting, feel free to explore!
This website is intentionally exposed within a specific network. Here are some additional details about the website and its purpose (replace with your actual content).
<p>**Important Security Reminder:** Always be cautious when accessing exposed network websites. Take necessary precautions to protect your information.</p>
</h3>
</main>
</main>
<footer class="last">
<small>This is copyrighted by the laws of physics ©. It must not be pirated or copied in any way possible. Anyways.. pls dont copy this bc im gona gst sued!1!1</small>
</footer>
</body>
</html>
and /form/signUp.php:
$email = $_POST['email'];
$password = $_POST["password"];
$conn = new PDO("mysql:host=localhost;dbname=users", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO users (name, email, password) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
if ($_SERVER["REQUEST_METHOD"] === "POST") {
echo "<script>alert('Error: Please enter your name.');</script>";
$stmt->execute([$name, $email, $password]);
echo "<script>alert('User inserted successfully!'); window.location.href = '/../';</script>";
$_SESSION["name"] = $name;
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
header("Location: signUp.html");
<code>
<?php
session_start();
var_dump($_SERVER);
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST["password"];
try {
$conn = new PDO("mysql:host=localhost;dbname=users", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO users (name, email, password) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
if ($_SERVER["REQUEST_METHOD"] === "POST") {
if (empty($name)) {
echo "<script>alert('Error: Please enter your name.');</script>";
} else {
$stmt->execute([$name, $email, $password]);
echo "<script>alert('User inserted successfully!'); window.location.href = '/../';</script>";
$loggedin = true;
$_SESSION["name"] = $name;
}
}
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
exit();
} finally {
$conn = null;
}
header("Location: signUp.html");
exit();
?>
</code>
<?php
session_start();
var_dump($_SERVER);
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST["password"];
try {
$conn = new PDO("mysql:host=localhost;dbname=users", "root", "");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO users (name, email, password) VALUES (?, ?, ?)";
$stmt = $conn->prepare($sql);
if ($_SERVER["REQUEST_METHOD"] === "POST") {
if (empty($name)) {
echo "<script>alert('Error: Please enter your name.');</script>";
} else {
$stmt->execute([$name, $email, $password]);
echo "<script>alert('User inserted successfully!'); window.location.href = '/../';</script>";
$loggedin = true;
$_SESSION["name"] = $name;
}
}
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
exit();
} finally {
$conn = null;
}
header("Location: signUp.html");
exit();
?>
Tryna make it remember the session, didn’t even work.