0

I have an odd problem with PHP Sessions (using php 5.6) both in localhost and own webhost.

I create a new session, I echo it and it gets displayed. However when I head to Resources -> Cookies -> localhost/mydomain.com I only see PHPSESSID, and not the session I created.

<?php
session_start();

$_SESSION['test'] = "test";

echo $_SESSION['test'];
?>

Picture right after I run the code above:

enter image description here

What is wrong with what I do? Or is it a PHP or Chrome related issue?

Thank you.

1 Answer 1

2

PHP Sessions are server-side. It's not an issue, it's by design.

On the client side, meaning chrome or any other browser, there is only the session id. That's what is stored as "PHPSESSID"-Cookie if not modified. Everything else stays on the server. You can't access this from chome.

To see the session-data, you can create a php site with this content:

<?php
header('Content-Type: text/plain; charset=utf-8');
session_start();
var_dump($_SESSION);

Edit: This simple example only works if you don't save class instances inside your $_SESSION. In this case the classes must be defined before session_start().

Sign up to request clarification or add additional context in comments.

1 Comment

Hell, I believe I was confusing sessions with cookies. The cookies do appear there, but the sessions don't, which makes perfect sense. Thanks for the quick response!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.