Hello! I'm new to php. 1 time I call the session session_start() when connecting to the database, 2 times session_start() when registering and so on, I read that the session needs to be called every time, but everything is in one code, so right? and what will happen?
1 answer
Calling session_start() again will not lead to anything. If you try to execute the code
<? ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); session_start(); session_start(); That will get a warning
Notice: A session had already been started - ignoring session_start () in ...
This is because
Sessions that use files (by default in PHP) block the session file immediately when the session is opened using the session_start () function or indirectly when session.auto_start is specified. After blocking, no other script can access the same session file until it is closed either when the script is terminated or when the session_write_close () function is called.
http://php.net/manual/ru/session.examples.basic.php
ps First of all, try to contact the documentation. Most of the questions will disappear.
- And if I create sessions in different files and then connect them to 1 file of type
session_start(); $_SESSION["steamid"] = "YES"session_start(); $_SESSION["steamid"] = "YES"and in anothersession_start(); $_SESSION["login"] = "YES"session_start(); $_SESSION["login"] = "YES"and connect them to 1 file, it will be a mistake, because there are 2 sessions, but 1 is thesession_start()command? - Andrey B - And I don’t have such an error. Notice: A session had already been started - ignoring session_start () in ... - Andrey B
- @AndreyB, the session is still the same. Any number of variables and any data structures can be stored in the session - this is a regular file with serialize - Gedweb
- @Gedweb now you convinced me, ATP - Andrew B