Global Variable Session not remembering

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<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>
<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.

New contributor

Totoro Angelo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật