I created a session in
ENTRANCE PAGE
<?php
session_start();
include 'dbconfig.php';
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM login WHERE username = '$username' AND password= '$password' ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$_SESSION["userid"] = $row['user'];
echo $_SESSION["userid"];
}
} else {
echo "wrong";
}
$conn->close();
?>
LOGIN FETCHING
function login() {
var username = $("#username").val();
var password = $("#password").val();
if (username == "" || username == null || username == undefined || password == "" || password == null || password == undefined) {
$('#foremptyvalue').show();
} else {
$('#foremptyvalue').hide();
$('#loader').show();
jQuery.ajax({
url: baseurl + "login.php"
, data: 'username=' + username + '&password=' + password
, type: "POST"
, success: function (response) {
response = $.trim(response);
if (response == "wrong") {
$('#loader').hide();
$('#forwronginput').show();
$("#username").val('');
$("#password").val('');
} else {
$('#loader').hide();
$('#forwronginput').hide();
location.href = "account.php?id=" + response;
}
}
, error: function () {}
});
}
}
header.php
The session variable is not working on this page. I used the code below:
<?php
session_start();
echo session_id();
$session = $_SESSION["userid"];
?>
RESULT BELOW
ptarbkn67poq1gkch2dh6fvqc3 Note : Undefined index: userid in C: \ xampp \ htdocs \ feecounter \ header.php on line 4
I also check if the session save path is available or not, and it is writable. it saves the session to C: \ xampp \ tmp
source
share