Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shern91's avatar

Get Laravel Session by using AJAX/JS

I try to make a function when user logged in, store a time-stamp into a session, and every one hours after from the time stamp, will pop up a alert.

Now i can get a timestamp when user logged in, but now i want to pass that value to Ajax/js to let me finish the time count down function. Does everyone can help me or give me other solution? Thank in advance.

Edited: I was wrote wrong about the title and question, my timestamp is store in Laravel session, but i want to pass it to AJAX/JS, is this possible?

0 likes
2 replies
joedixon's avatar
joedixon
Best Answer
Level 5

If your JS is in your template, you can create a JS variable and assign it the value of the timestamp from the session like so:

var timestamp = '{{ Session::get('timestamp');}}';

Otherwise, create a route that just returns the timestamp from the session:

return \Session::get('timestamp');

And use ajax to grab the timestamp on page load.

Hope this helps.

2 likes
shern91's avatar

joedixon

Thank for your reply. I will try your suggestion.

Please or to participate in this conversation.