I am trying to set the user's info in session variable because I am gonna use it in another page but I am getting issue related to header.
When can we destroy the session the error:
Warning: session_start(): Session cannot be started after headers have already been sent
Here is my registration.php code
<?php
session_start();
?>
<?php
if (isset($_POST["register-submit"])) {
global $wpdb;
$username = esc_sql($_POST["username"]);
$shopname = esc_sql($_POST["shopname"]);
$gstnumber = esc_sql($_POST["gstnumber"]);
$phonenumber = esc_sql($_POST["phonenumber"]);
$password = esc_sql($_POST["password"]);
$conf_password = esc_sql($_POST["conf_password"]);
$api_key = "{api_key}";
$endpoint_url = 'http://sheet.gstincheck.co.in/check/' . $api_key . '/' . $gstnumber;
$_SESSION['user_data'] = array(
'username' => $username,
'shopname' => $shopname,
'gstnumber' => $gstnumber,
'phonenumber' => $phonenumber,
'password' => $password
);
if ($password == $conf_password) {
$response = file_get_contents($endpoint_url);
$data = json_decode($response, true);
if (!username_exists($username)) {
if ($data['flag'] == true) {
} else {
echo '<script>alert("GST NO is invalid")</script>';
}
} else {
echo '<script>alert("Username alredy Exists")</script>';
}
} else {
echo '<script>alert("pass do not matched")</script>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
</head>
<body>
<div class="registration-container">
<h2>Registration</h2>
<form action="" method="POST">
<--My Form Input-->
</form>
<p>Already have an account? <a href="your-login-page">Login here</a></p>
</div>
</body>
</html>