I am trying to pass a variable to a php session variable, so I can access it later from other functions. I might have a totally approach, I'm not sure. What I want to do is to have my vaiable stored somewhere so I can access it anytime and anywhere within a session. This is what I have now:
$(".small-item-card .bookmark").click(function(e){
e.preventDefault();
let el_id = $(this).attr("element-id");
$.ajax({
type: 'post',
url: '/session.php',
data: {el_id: el_id},
success:function(data) {
console.log(data);
}
});
PHP - session.php
<?
session_start();
$element_id = (isset($_POST['el_id']) ? $_POST['el_id'] : "empty");
$_SESSION['element_ids'] = $element_id;
echo $_SESSION['element_ids'];
?>
When I open session.php page it prints "empty". What am I doing wrong?
data: {el_id: "test"},$_SESSION['element_ids'] = "test".