Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View and change sessions variables in a browser

Debugging a PHP program, is there any add-on/plug-in for browser which I can view sessions variables (those PHP $_SESSION["foobar"] )?

Best if I can change the value in the variables.

like image 960
ohho Avatar asked Mar 12 '10 03:03

ohho


People also ask

Can I change session value in browser?

There is no way to manipulate the values stored in sessions from the client side. That's one of the main reasons you'd use a session over a cookie - YOU control the data. With cookies, the user can manipulate the data.

How can I see session variables in browser?

# View sessionStorage keys and valuesClick the Application tab to open the Application panel. Expand the Session Storage menu. Click a domain to view its key-value pairs. Click a row of the table to view the value in the viewer below the table.

Can you change session variables?

Session variables on the client are read-only. They cannot be modified. In order to change the value of a session variable, an Ajax Callback is required. Similarly, if a session variable changes on the server, it will not be updated on the client until an Ajax Callback is made from the client.


2 Answers

There is no way to manipulate the values stored in sessions from the client side.

That's one of the main reasons you'd use a session over a cookie - YOU control the data. With cookies, the user can manipulate the data.

The only way to access/manipulate session data from the client side would be with an Ajax call or other JavaScript mechanism to call another php script, which would be doing the retrieval/manipulation of the session data via the session_ functions.

like image 69
Jacob Relkin Avatar answered Sep 27 '22 23:09

Jacob Relkin


$_SESSION is a server-side array of variables. If we could read or change the values, there are many things that we could do to hack or cause other bad things to happen.

However, using phpinfo(); we can view session variables - but we cannot change the value.

Even better, we can debug all session variables with

print_r($_SESSION);  //if you echo "<pre>" before, and a closing "</pre>" after, it prints very cleanly. 

some other useful commands:

session_start(); // start session  -- returns Session ID session_destroy(); // unset all session variable 

Session is an array so if you set $_SESSION['key']='value'; it is same like $array['key']=value; - only, what is special about $_SESSION - is that it persists until the window is closed, or session_destroy() is called.

like image 45
apis17 Avatar answered Sep 28 '22 00:09

apis17