0

i have a php script that is using

$_SESSION["username"] = $username;

for declare the session, and work fine, but if you close the navigator the session is removed, and i cant see why, my php.ini is this php.ini

atra
  • 1
  • What does the `$_SESSION["username"]` prints after you close the navigator? Btw you mean after closing the browser? – Abrar May 26 '18 at 16:42
  • yea, if u close the tab the and open a new one the session still but, if u close the tab and browser the session is gone, $_SESSION["username"] is a input username post – atra May 26 '18 at 16:43
  • 1
    Possible duplicate of [PHP - Session destroy after closing browser](https://stackoverflow.com/questions/24402047/php-session-destroy-after-closing-browser) – Raffi May 26 '18 at 16:52

2 Answers2

0

This is because sessions are not permanent. A session is tied to the browser you have open. Once you close it, the session is gone.

If you want to keep some information permanently. You will want to use a database and store the information there.

Daniel Dees
  • 182
  • 2
  • 14
  • the session should still, you can try anything like facebooks sessions, and the input username is with sql – atra May 26 '18 at 16:45
  • @atra those are not sessions. Cookies store data in the browser if it gets closed. That is what most sites use for login data. – Daniel Dees May 26 '18 at 16:46
  • so i should use cookies for store sessions ? – atra May 26 '18 at 16:47
  • @atra if you want to simply have the browser remember a person's login details so they don't have to put in their username/password each time they visit your site, then yes, use Cookies. – Daniel Dees May 26 '18 at 16:48
  • so ex facebook use cookies for store theirs sessions ? – atra May 26 '18 at 16:48
  • @atra First off, sessions and cookies are different things. But for what you are asking, yes Facebook uses cookies. – Daniel Dees May 26 '18 at 16:50
  • okey ty, i dont have exxpereicen using cookies i will check it – atra May 26 '18 at 16:51
0

Session is automatically destroyed after you close browser, for permanent storage use a database(mysql)

Mardo
  • 9
  • 5
  • the login username is stored on sql – atra May 26 '18 at 16:48
  • When you close browser and open it ...are you logged in? Or logged out? – Mardo May 26 '18 at 16:49
  • if i close the tab but not the broswer logged, if i close all the brrowse logged out – atra May 26 '18 at 16:50
  • Yeah, so once logged out session variable gets destroyed , you will need to again login to make it get printed....Use cookie so that you dont logout even after closing browser. – Mardo May 26 '18 at 16:51
  • yea i will use cookies ty! :D, bbtw i read that cookies are vulnerable ? – atra May 26 '18 at 16:53
  • https://stackoverflow.com/questions/1354999/keep-me-logged-in-the-best-approach read it – Mardo May 26 '18 at 16:54