session in php works only on the same page, but does not work on other pages in the same websitePHP session lost after redirectwhen I send value from a page to another page using session, the following error appearsHow do I expire a PHP session after 30 minutes?PHP session echo not working?Reference — What does this symbol mean in PHP?Check if PHP session has already startedHow does PHP 'foreach' actually work?Reference - What does this error mean in PHP?Why PHP include is working on local server and not on websiteCannot set session variables in a page that is handling session.upload_progress.namePHP - Session variables not carrying over to next page on one device, but does on anotherPHP Session variable is empty after redirecting to another page
Sleeping solo in a double sleeping bag
Is there such a thing as too inconvenient?
Why don't politicians push for fossil fuel reduction by pointing out their scarcity?
What does it mean to have a subnet mask /32?
Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?
Metal that glows when near pieces of itself
Why are delta bots so finicky?
How to "know" if I have a passion?
Should my "average" PC be able to discern the potential of encountering a gelatinous cube from subtle clues?
Was Tuvok bluffing when he said that Voyager's transporters rendered the Kazon weapons useless?
What is the evidence on the danger of feeding whole blueberries and grapes to infants and toddlers?
The teacher logged me in as administrator for doing a short task, is the whole system now compromised?
Chess software to analyze games
How to persuade recruiters to send me the Job Description?
Can you feel passing through the sound barrier in an F-16?
Can we save the word "unique"?
Why does my house heat up, even when it's cool outside?
How to get the pandadocs from an opportunity?
What is "Wayfinder's Guide to Eberron"?
Why we don't have vaccination against all diseases which are caused by microbes?
In an emergency, how do I find and share my position?
Does Swashbuckler's Fancy Footwork apply if the attack was made with Booming Blade?
Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?
How to specify and fit a hybrid machine learning - linear model
session in php works only on the same page, but does not work on other pages in the same website
PHP session lost after redirectwhen I send value from a page to another page using session, the following error appearsHow do I expire a PHP session after 30 minutes?PHP session echo not working?Reference — What does this symbol mean in PHP?Check if PHP session has already startedHow does PHP 'foreach' actually work?Reference - What does this error mean in PHP?Why PHP include is working on local server and not on websiteCannot set session variables in a page that is handling session.upload_progress.namePHP - Session variables not carrying over to next page on one device, but does on anotherPHP Session variable is empty after redirecting to another page
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have two simple pages(test.php, test2.php).
test.php
<?php
session_start();
$_SESSION['username'] = "wria";
echo '<a href = "test2.php">click to another page</a> <br>';
if($_SESSION['username'])
echo $_SESSION['username'];
?>
test2.php
<?php
session_start();
var_dump($_SESSION);
if($_SESSION['username'])
echo $_SESSION['username'];
?>
in the output,
when I open test.php, after a refresh
but when I go to test2.php, the output appears:
nothing showing.
Note: this file is on real hosting not local.
php session
add a comment |
I have two simple pages(test.php, test2.php).
test.php
<?php
session_start();
$_SESSION['username'] = "wria";
echo '<a href = "test2.php">click to another page</a> <br>';
if($_SESSION['username'])
echo $_SESSION['username'];
?>
test2.php
<?php
session_start();
var_dump($_SESSION);
if($_SESSION['username'])
echo $_SESSION['username'];
?>
in the output,
when I open test.php, after a refresh
but when I go to test2.php, the output appears:
nothing showing.
Note: this file is on real hosting not local.
php session
2
error_reporting(E_ALL); ini_set('display_errors', '1');
– AbraCadaver
Mar 27 at 15:22
2
Are you sure that is all the code in those 2 files?
– RiggsFolly
Mar 27 at 15:23
yes that is all codes which I have.
– Wria Mohammed
Mar 27 at 15:25
Check te protocoll HTTP/HTTPS in href="" or domain is with/without www
– Gabor
Mar 27 at 15:26
Any errors yet?
– AbraCadaver
Mar 27 at 15:33
add a comment |
I have two simple pages(test.php, test2.php).
test.php
<?php
session_start();
$_SESSION['username'] = "wria";
echo '<a href = "test2.php">click to another page</a> <br>';
if($_SESSION['username'])
echo $_SESSION['username'];
?>
test2.php
<?php
session_start();
var_dump($_SESSION);
if($_SESSION['username'])
echo $_SESSION['username'];
?>
in the output,
when I open test.php, after a refresh
but when I go to test2.php, the output appears:
nothing showing.
Note: this file is on real hosting not local.
php session
I have two simple pages(test.php, test2.php).
test.php
<?php
session_start();
$_SESSION['username'] = "wria";
echo '<a href = "test2.php">click to another page</a> <br>';
if($_SESSION['username'])
echo $_SESSION['username'];
?>
test2.php
<?php
session_start();
var_dump($_SESSION);
if($_SESSION['username'])
echo $_SESSION['username'];
?>
in the output,
when I open test.php, after a refresh
but when I go to test2.php, the output appears:
nothing showing.
Note: this file is on real hosting not local.
php session
php session
edited Mar 27 at 15:22
Wria Mohammed
asked Mar 27 at 15:17
Wria MohammedWria Mohammed
3484 silver badges13 bronze badges
3484 silver badges13 bronze badges
2
error_reporting(E_ALL); ini_set('display_errors', '1');
– AbraCadaver
Mar 27 at 15:22
2
Are you sure that is all the code in those 2 files?
– RiggsFolly
Mar 27 at 15:23
yes that is all codes which I have.
– Wria Mohammed
Mar 27 at 15:25
Check te protocoll HTTP/HTTPS in href="" or domain is with/without www
– Gabor
Mar 27 at 15:26
Any errors yet?
– AbraCadaver
Mar 27 at 15:33
add a comment |
2
error_reporting(E_ALL); ini_set('display_errors', '1');
– AbraCadaver
Mar 27 at 15:22
2
Are you sure that is all the code in those 2 files?
– RiggsFolly
Mar 27 at 15:23
yes that is all codes which I have.
– Wria Mohammed
Mar 27 at 15:25
Check te protocoll HTTP/HTTPS in href="" or domain is with/without www
– Gabor
Mar 27 at 15:26
Any errors yet?
– AbraCadaver
Mar 27 at 15:33
2
2
error_reporting(E_ALL); ini_set('display_errors', '1');
– AbraCadaver
Mar 27 at 15:22
error_reporting(E_ALL); ini_set('display_errors', '1');
– AbraCadaver
Mar 27 at 15:22
2
2
Are you sure that is all the code in those 2 files?
– RiggsFolly
Mar 27 at 15:23
Are you sure that is all the code in those 2 files?
– RiggsFolly
Mar 27 at 15:23
yes that is all codes which I have.
– Wria Mohammed
Mar 27 at 15:25
yes that is all codes which I have.
– Wria Mohammed
Mar 27 at 15:25
Check te protocoll HTTP/HTTPS in href="" or domain is with/without www
– Gabor
Mar 27 at 15:26
Check te protocoll HTTP/HTTPS in href="" or domain is with/without www
– Gabor
Mar 27 at 15:26
Any errors yet?
– AbraCadaver
Mar 27 at 15:33
Any errors yet?
– AbraCadaver
Mar 27 at 15:33
add a comment |
4 Answers
4
active
oldest
votes
I think the problem comes from your server configuration. Have you tried it in a local environement ? Here's is some steps to help you debug this which comes from PHP session lost after redirect
First, carry out these usual checks:
- Make sure session_start(); is called before any sessions are being called. So a safe bet would be to put it at the beginning of your page, immediately after the opening
- After the header redirect, end the current script using exit(); (Others have also suggested session_write_close(); and session_regenerate_id(true), you can try those as well, but I'd use exit();)
- Make sure cookies are enabled in the browser you are using to test it on.
- Ensure register_globals is off, you can check this on the php.ini file and also using phpinfo().
- Make sure you didn't delete or empty the session
- Make sure the key in your $_SESSION superglobal array is not overwritten anywhere
- Make sure you redirect to the same domain. So redirecting from a www.yourdomain.com to yourdomain.com doesn't carry the session forward.
- Make sure your file extension is .php (it happens!)
You may also have to configure a session_save_path like it was said in the post i linked.
1
thank you, i tried.
– Wria Mohammed
Mar 29 at 10:57
add a comment |
if you add this code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
to the top for test2.php, you will see your error.
if you see (No such file or directory) it means your saved session is unavailable, you can change it for another place.
or probably you do not have permission for the folder that session will save on it.
thank you, your answer is good, I tried. it is correct. thank you again.
– Wria Mohammed
Mar 29 at 21:08
add a comment |
your path to save session is unavailable. You have to change it for an available place.
You can change in php.ini
thank you. that is the point.
– Wria Mohammed
Mar 30 at 22:09
1
you are most welcome
– Faxradin majid
Mar 30 at 22:37
add a comment |
Likely you do not persist a session id in any way and the new session is being opened each time.
Please have a look at the https://www.php.net/manual/en/session.idpassing.php
There are a few ways it can be 'solved', using cookies, GET parameter etc.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380712%2fsession-in-php-works-only-on-the-same-page-but-does-not-work-on-other-pages-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think the problem comes from your server configuration. Have you tried it in a local environement ? Here's is some steps to help you debug this which comes from PHP session lost after redirect
First, carry out these usual checks:
- Make sure session_start(); is called before any sessions are being called. So a safe bet would be to put it at the beginning of your page, immediately after the opening
- After the header redirect, end the current script using exit(); (Others have also suggested session_write_close(); and session_regenerate_id(true), you can try those as well, but I'd use exit();)
- Make sure cookies are enabled in the browser you are using to test it on.
- Ensure register_globals is off, you can check this on the php.ini file and also using phpinfo().
- Make sure you didn't delete or empty the session
- Make sure the key in your $_SESSION superglobal array is not overwritten anywhere
- Make sure you redirect to the same domain. So redirecting from a www.yourdomain.com to yourdomain.com doesn't carry the session forward.
- Make sure your file extension is .php (it happens!)
You may also have to configure a session_save_path like it was said in the post i linked.
1
thank you, i tried.
– Wria Mohammed
Mar 29 at 10:57
add a comment |
I think the problem comes from your server configuration. Have you tried it in a local environement ? Here's is some steps to help you debug this which comes from PHP session lost after redirect
First, carry out these usual checks:
- Make sure session_start(); is called before any sessions are being called. So a safe bet would be to put it at the beginning of your page, immediately after the opening
- After the header redirect, end the current script using exit(); (Others have also suggested session_write_close(); and session_regenerate_id(true), you can try those as well, but I'd use exit();)
- Make sure cookies are enabled in the browser you are using to test it on.
- Ensure register_globals is off, you can check this on the php.ini file and also using phpinfo().
- Make sure you didn't delete or empty the session
- Make sure the key in your $_SESSION superglobal array is not overwritten anywhere
- Make sure you redirect to the same domain. So redirecting from a www.yourdomain.com to yourdomain.com doesn't carry the session forward.
- Make sure your file extension is .php (it happens!)
You may also have to configure a session_save_path like it was said in the post i linked.
1
thank you, i tried.
– Wria Mohammed
Mar 29 at 10:57
add a comment |
I think the problem comes from your server configuration. Have you tried it in a local environement ? Here's is some steps to help you debug this which comes from PHP session lost after redirect
First, carry out these usual checks:
- Make sure session_start(); is called before any sessions are being called. So a safe bet would be to put it at the beginning of your page, immediately after the opening
- After the header redirect, end the current script using exit(); (Others have also suggested session_write_close(); and session_regenerate_id(true), you can try those as well, but I'd use exit();)
- Make sure cookies are enabled in the browser you are using to test it on.
- Ensure register_globals is off, you can check this on the php.ini file and also using phpinfo().
- Make sure you didn't delete or empty the session
- Make sure the key in your $_SESSION superglobal array is not overwritten anywhere
- Make sure you redirect to the same domain. So redirecting from a www.yourdomain.com to yourdomain.com doesn't carry the session forward.
- Make sure your file extension is .php (it happens!)
You may also have to configure a session_save_path like it was said in the post i linked.
I think the problem comes from your server configuration. Have you tried it in a local environement ? Here's is some steps to help you debug this which comes from PHP session lost after redirect
First, carry out these usual checks:
- Make sure session_start(); is called before any sessions are being called. So a safe bet would be to put it at the beginning of your page, immediately after the opening
- After the header redirect, end the current script using exit(); (Others have also suggested session_write_close(); and session_regenerate_id(true), you can try those as well, but I'd use exit();)
- Make sure cookies are enabled in the browser you are using to test it on.
- Ensure register_globals is off, you can check this on the php.ini file and also using phpinfo().
- Make sure you didn't delete or empty the session
- Make sure the key in your $_SESSION superglobal array is not overwritten anywhere
- Make sure you redirect to the same domain. So redirecting from a www.yourdomain.com to yourdomain.com doesn't carry the session forward.
- Make sure your file extension is .php (it happens!)
You may also have to configure a session_save_path like it was said in the post i linked.
answered Mar 27 at 15:39
ThomasThomas
658 bronze badges
658 bronze badges
1
thank you, i tried.
– Wria Mohammed
Mar 29 at 10:57
add a comment |
1
thank you, i tried.
– Wria Mohammed
Mar 29 at 10:57
1
1
thank you, i tried.
– Wria Mohammed
Mar 29 at 10:57
thank you, i tried.
– Wria Mohammed
Mar 29 at 10:57
add a comment |
if you add this code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
to the top for test2.php, you will see your error.
if you see (No such file or directory) it means your saved session is unavailable, you can change it for another place.
or probably you do not have permission for the folder that session will save on it.
thank you, your answer is good, I tried. it is correct. thank you again.
– Wria Mohammed
Mar 29 at 21:08
add a comment |
if you add this code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
to the top for test2.php, you will see your error.
if you see (No such file or directory) it means your saved session is unavailable, you can change it for another place.
or probably you do not have permission for the folder that session will save on it.
thank you, your answer is good, I tried. it is correct. thank you again.
– Wria Mohammed
Mar 29 at 21:08
add a comment |
if you add this code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
to the top for test2.php, you will see your error.
if you see (No such file or directory) it means your saved session is unavailable, you can change it for another place.
or probably you do not have permission for the folder that session will save on it.
if you add this code:
error_reporting(E_ALL);
ini_set('display_errors', 1);
to the top for test2.php, you will see your error.
if you see (No such file or directory) it means your saved session is unavailable, you can change it for another place.
or probably you do not have permission for the folder that session will save on it.
answered Mar 29 at 18:07
DostiDosti
358 bronze badges
358 bronze badges
thank you, your answer is good, I tried. it is correct. thank you again.
– Wria Mohammed
Mar 29 at 21:08
add a comment |
thank you, your answer is good, I tried. it is correct. thank you again.
– Wria Mohammed
Mar 29 at 21:08
thank you, your answer is good, I tried. it is correct. thank you again.
– Wria Mohammed
Mar 29 at 21:08
thank you, your answer is good, I tried. it is correct. thank you again.
– Wria Mohammed
Mar 29 at 21:08
add a comment |
your path to save session is unavailable. You have to change it for an available place.
You can change in php.ini
thank you. that is the point.
– Wria Mohammed
Mar 30 at 22:09
1
you are most welcome
– Faxradin majid
Mar 30 at 22:37
add a comment |
your path to save session is unavailable. You have to change it for an available place.
You can change in php.ini
thank you. that is the point.
– Wria Mohammed
Mar 30 at 22:09
1
you are most welcome
– Faxradin majid
Mar 30 at 22:37
add a comment |
your path to save session is unavailable. You have to change it for an available place.
You can change in php.ini
your path to save session is unavailable. You have to change it for an available place.
You can change in php.ini
answered Mar 30 at 21:42
Faxradin majidFaxradin majid
393 bronze badges
393 bronze badges
thank you. that is the point.
– Wria Mohammed
Mar 30 at 22:09
1
you are most welcome
– Faxradin majid
Mar 30 at 22:37
add a comment |
thank you. that is the point.
– Wria Mohammed
Mar 30 at 22:09
1
you are most welcome
– Faxradin majid
Mar 30 at 22:37
thank you. that is the point.
– Wria Mohammed
Mar 30 at 22:09
thank you. that is the point.
– Wria Mohammed
Mar 30 at 22:09
1
1
you are most welcome
– Faxradin majid
Mar 30 at 22:37
you are most welcome
– Faxradin majid
Mar 30 at 22:37
add a comment |
Likely you do not persist a session id in any way and the new session is being opened each time.
Please have a look at the https://www.php.net/manual/en/session.idpassing.php
There are a few ways it can be 'solved', using cookies, GET parameter etc.
add a comment |
Likely you do not persist a session id in any way and the new session is being opened each time.
Please have a look at the https://www.php.net/manual/en/session.idpassing.php
There are a few ways it can be 'solved', using cookies, GET parameter etc.
add a comment |
Likely you do not persist a session id in any way and the new session is being opened each time.
Please have a look at the https://www.php.net/manual/en/session.idpassing.php
There are a few ways it can be 'solved', using cookies, GET parameter etc.
Likely you do not persist a session id in any way and the new session is being opened each time.
Please have a look at the https://www.php.net/manual/en/session.idpassing.php
There are a few ways it can be 'solved', using cookies, GET parameter etc.
answered Mar 27 at 15:24
matiitmatiit
6,1235 gold badges32 silver badges60 bronze badges
6,1235 gold badges32 silver badges60 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55380712%2fsession-in-php-works-only-on-the-same-page-but-does-not-work-on-other-pages-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
error_reporting(E_ALL); ini_set('display_errors', '1');
– AbraCadaver
Mar 27 at 15:22
2
Are you sure that is all the code in those 2 files?
– RiggsFolly
Mar 27 at 15:23
yes that is all codes which I have.
– Wria Mohammed
Mar 27 at 15:25
Check te protocoll HTTP/HTTPS in href="" or domain is with/without www
– Gabor
Mar 27 at 15:26
Any errors yet?
– AbraCadaver
Mar 27 at 15:33