I need to set a php session using jquery ajax
in the code below everything works - but seems - the session is not created
what is wrong, pls ?
music.php
session_start();
if(isset($_SESSION['ad'])){echo $_SESSION['ad'];} // nothing is echoed
include('music_pro.php');
music.js
var str = 'lorem';
$.post('music_pro.php', {fn: 'admin_prompt', args: [str]}, function(data){
console.log(data); // ok
if(data == 'ok'){location.href = location.href;}
});
music_pro.php
if(isset($_POST['fn'], $_POST['args'])){
$fn = $_POST['fn']; $args = $_POST['args'];
$fn(...$args);
}
function admin_prompt($str){
if($str == 'lorem'){
$_SESSION['ad'] = 1; // seems this line doesn't work
echo 'ok';
}
}