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

AwadGorg's avatar

How can i print the session key and value in the screen

Hello, I've set a session key and value and then print to the screen session()->get(keyname); and this only return to me the keyname value and i want both to be returned cuz both of them are dynamic and am using them both to make another action does there anyway that i can get the session key and value,

what i want is to use them in where clause to get data from database

0 likes
3 replies
Sinnbeck's avatar

Well you already know the keyname as you use it in the get()?

{{session()->get($keyname) }} - {{$keyname}}
Snapey's avatar

How could you get it from session if you did not know what it was called?

Can you give us more context?

AwadGorg's avatar

am making filter system with multi select or check box the user can check box1 and search with it and the the user check box2 now it should search with box 1 and box2

the way I've decided to make it is when the user clicks on box1 it send get request with ajax that holds the row name that the user want to search in and the id (value) and use the selector and the id to search in the db table and return result to the user, then when the user check box2 it also save the selector and the id of box2 in a session, I want to use the session key in this case its the table row and the session value the id, to search for both box1 and box2, here is part of my code hope it will make it more clear

$(document).ready(function(){
    $(".genral").click(function(){
        
        $("#overlay").fadeIn(300); 
        var elmId = $(this).attr("id");
            var livesearchVal = $("#livesearch").val();
            var types = $(this).attr("data-type");
            var selector = $(this).attr("data-uniqe");
        console.log(url + 'hey');
        $.ajax({
            
            type: 'GET',
            url: "/ajax/genaral_specializations2.php?id="+elmId+'&term='+livesearchVal+'&types='+types+'&selector='+selector,
            success: function(data){
               $("#paginate_books").html(data);
               $("#overlay").fadeOut(300); 
            }
        });
    });
});

var elmid = the value of the checkbox, var term = it's the search term that user entered in the input text (not important) var types = (not important) var selector = the table row name for example (table cast row name),

below is part of the controller controller

        $gen_spci_no = $_GET['id'];
        $table_uniqe = $_GET['selector'];
        session()->put($table_uniqe, $gen_spci_no);
        $input = collect($filter_sessions)->filter(function($value) {
            return null !== $value;
})->toArray();

like you see above I put the new session box2 alongside box1 I already know all the session names so am gonna loop throw them and get the once that already been set and assign them to the $input array this array should hold the session key and name like this

$input = array($sessionkey => $sessionval);

Please or to participate in this conversation.