Im using a jQuery Vector Map Library with name jqvmap. Anyone knows a way to Set a Session in Javascript instead of setting a Cookie?:
My code:
function getCountryName(code) {
var path = JQVMap.maps["world_en"].paths[code];
return path && path.name;
}
var fromCountryCode = getCookie(cookieName) || "";
worldMap = jQuery('#vmap').vectorMap({
map: "world_en",
backgroundColor: '#FFCC28',
borderColor: '#818181',
scaleColors: ['#222222', '#ffffff'],
borderOpacity: 0.25,
color: '#2F3132',
hoverOpacity: 0.8,
multiSelectRegion: true,
selectedColor: '#FBB24B',
selectedRegions: '{{$flag}}',
//selectedRegions: [fromCountryCode],
enableZoom: true,
showTooltip: true,
onRegionClick: function(e, code, name) {
code == "AE" ||
code == "AF" ||
code == "AG" ||
code == "AL" ||
code == "AM" ||
code == "AO" ||
code == "AR" ||
code == "AT" ||
code == "AU" ||
etc...
code == "ZW"
$("#message").text("Your Country: " + name);
setCookie(cookieName, code, 600); // minutes
window.location.replace("https://example.com/");
}
});
My idea is to Set a Session in Javascript instead of setting a Cookie by replacing the following part of code:
setCookie(cookieName, code, 600);
replaced by
session(['name' => $code]);
I read SO and it seems that sessions cannot be altered from client side, but probably someone knows a workaround using AJAX. brgds.
Well, TBH I haven't fully understand the whole workflow of Your application, but if You need to create a PHP cookie-less session, You will need to pass back & forth the session id by yourself. This can be done using ajax/php like below. Create two PHP pages:
set_session.php:
get_session.php:
JavaScript:
Fisrt, You should get a session id into
mySessionId:then, You can reuse this session id later from Your html page to recall the session variables stored server-side:
Moreover, depending from Your needs, You can also use an http header to redirect the user to the new link from directly inside the
get_session.phppage.Hope this helps.