Know all the $_SESSION

Asked

Viewed 667 times

0

I have a doubt and I searched and I found no corner an answer, I wanted to know if it is possible to give a echo $_SESSION and know all the session that my browser has at that moment and if yes as?

  • print_r($_SESSION), var_dump($_SESSION)?

2 answers

4


Can use var_dump or print_r, thus:

<?php
session_start();

var_dump($_SESSION);

Or so:

<?php
session_start();

print_r($_SESSION);

The print_r is easier to read, because it contains less details, idela for those who just want to see the same content, already the var_dump is ideal for analyzing variables, values such as strings, int, float, size, etc.

  • I would quote the var_export also, given the ease of copying and playing in the interpreter to test :D

  • @Andersoncarloswoss think about var_export in cases where we need you to maintain a syntax that can be executed in PHP itself later, for example a system that edits variables from a configuration file in . php, an example: https://stackoverflow.com/a/43458974/1518921 (for the record, preg_replace there is because of OCD syndrome, I hate , in the last item of an array :P)

0

As William said above, if you just want to see, the print_r or var_dump will follow. If you want to use in your application, just keep in mind that for all purposes the $_SESSION variable can be treated as a common PHP array.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.