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

Martha's avatar

The best way to save authorized user data without using session

Hello larafans :D

I am using session to save login user data such as (name , picture , score,..etc) , so there are some user data like score updating while user login.

I want to know the best way to save and track user data but under those conditions: 1- without using sessions , it work fine but when score updated sometimes (not all) it makes a critical bug beside I read it's not the best practice to use sessions. 2- without having to call server (database) each time I want those user data as those data is needed for almost all website pages , so it will be so bad performance.

so what is the best way to save user profile data if my structure for website : 1- standalone laravel project for api 2- standalone laravel project for front end

Thanks

0 likes
8 replies
d3xt3r's avatar

Persistent options and reliability go hand in hand but generally in opposite directions.

Simplest solution will be to add a table in database for storing profile info,either link it to session or user.

without having to call server (database) each time I want those user data as those data is needed for almost all website pages

use cache for select query, invalidate it when an update is made.

Martha's avatar

@d3xt3r thanks, may you give me more hints or keywords how to implement yours suggested solution .

1 like
d3xt3r's avatar

Some more insight on what you are actually doing would be needed in order to help better...

Martha's avatar

@d3xt3r Databse structure is user table that has current score attribute , this score is updated when user pass certain tests . required is : in front end after user passing the test show him the result in pop up as follow : his last score increased to be the new score

d3xt3r's avatar

Databse structure is user table that has current score attribute , this score is updated when user pass certain tests .

I hope you have no problem with this, you can update the score using the model increment(), decrement() function.

without having to call server (database) each time I want those user data as those data is needed for almost all website pages , so it will be so bad performance.

If you are using session for authentication, then you are already pulling in the user on each page load, you need not worry about extra db queries.

Martha's avatar

ok , the user score is working perfectly in header with session solution , but as the same time within the pop up I told you about "result pop up" sometimes it keep increasing the last score (before updating) to ... infinity (non stop ) ?!

d3xt3r's avatar

I can't comment without having seen both backend and front-end code :(

Martha's avatar

@d3xt3r when user login

Session::put('score', $score);

before my pop up template (other template page -test template)

  $old_score= Session::put('old_score' , Session::get('score));

my pop up template

         $old_score = Session::get("old_score") 
         $new_score = Session::get("score");
         echo '<div id="old_score" style="display: none" data-body= "'.$old_score.'">'.'</div>';
         echo '<div id="new_xp" style="display: none" data-body= "'.$new_score.'">'.'</div>';
$(document).ready(function () { var status = $('#status').data("body"); if(status == 'Success') { $('#myGrade').modal(); $('#slide2').attr('checked',false); $('#slide1').attr('checked',true); setTimeout(function(){ $('#body1').slideUp('slow'); }, 6000); setTimeout(function(){ $('#slide1').attr('checked',false); $('#slide2').attr('checked',true); $('#body2').slideDown('slow'); if(old_score == new_score) { $('#score').text(old_score); } else {setInterval(increase_score , 300);}
      }

    });

$('#slide1').click(function() { setTimeout(function(){ $('#body2').slideUp('slow') }, 10); setTimeout(function(){ $('#body1').slideDown('slow') }, 100); });

$('#slide2').click(function() { setTimeout(function(){ $('#body1').slideUp('slow') }, 10); current_score = old_score; setTimeout(function(){ $('#body2').slideDown('slow'); setInterval(increase_score , 300); });

function increase_score() { if(current_score == new_score) return; current_score++; $('#score').text(current_score); }

Please or to participate in this conversation.