D
D
Don2Quixote2018-04-02 21:32:08
PHP
Don2Quixote, 2018-04-02 21:32:08

How to make php sessions work on all pages of the site?

For example, I have an index.php page;
From this page an ajax request is sent to act.php;
A session and a variable are created on act.php $_SESSION[thing];
How to make it so that it $_SESSION[thing]could be used on any page (index.php, page.php ...), and not just on act.php
PS - while writing, I realized that I can create cookie in act.php. If there is any special solution to this problem - write.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita, 2018-04-02
@Don2Quixote

//act.php page.
session_start(); //declare session start
$_SESSION['test']='Hello world!'; //we write the value to the global array
can now be written at the beginning of the page on any page where we want to get our value -
session_start();
and by key, get the required value from the global $_SESSION array,
for example, we get what we wrote
//index.php page
session_start();
$_SESSION['test'];
I advise you to read phpfaq.ru/sessions The
example above is very simple, in reality you need to do checks and all that

B
Boris Syomov, 2018-04-02
@kotomyava

Probably, either you need to use php.net/manual/ru/session.configuration.php#ini.se... , or start a session in each file using php.net/manual/ru/function.session-start.php , and even better, generally have a single entry point where the session will be launched, routing, etc. will be processed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question