Jump to content

Recommended Posts

Hi fellow PHP Freaks. I am Jayson, 20 years old and I am new to PHP. My question more about the PHP Session.

 

I am aware of the difference of the Cookies and Session, that cookies are stored in the client side and session on the server side.

 

In cookies, it easy to distinguish users since it is managed or stored in the client side, however, in session it is stored in the server side. If so, how do we determine these data stored by session belongs to a particular user?

 

Can we store session ids?

 

I hope my problem was delivered clearly. Thank you.

Link to comment
https://forums.phpfreaks.com/topic/198479-session-vs-cookies-need-help/
Share on other sites

The accessable session is just a superglobal array. You can access it like so:

session_start();
$_SESSION['key'] = $value;
$_SESSION[1][2] = "Value";

 

If you're calling session_start() (thus starting the session) it will send a cookie to the user with the PHP Session ID. Using cookies is very much the same thing, but is obviously prone to being viewed by users, so it is best to store information in sessions that should be used in-application, such as data retrieved/or to be sent to the database.

 

Cookies or sessions are just your preferrence.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.