php Session variable become undefined when click to another link
I have designed a bilingual website initially loading in Arabic language by declaring a session variable 'language'.The index page load correctly ,but when i click the button to convert the language i'am getting the session variable undefined.please help me to fix this issue.
This below function load the home page.here am getting the session variable in the home page.
public function index(){
$_SESSION['page'] = 'Home';
if(empty( $_SESSION["language"])){
$_SESSION["language"] = "_ar";
}
$this->load->view('site'.$_SESSION["language"].'/index',$data);
}
In the home page when i click the language convert button it call the below controller function,but the session variable become undefined in this controller function.
When i open in i
public function lang_change_ar_to_eng() {
if ($_SESSION["language"] == "_en")
$_SESSION["language"] = "_ar";
else if($_SESSION["language"] == "_ar")
$_SESSION["language"] = "_en";
echo json_encode($_SESSION["language"]);
}
when i open in incognito window i got the session variables,i don't know what's the issue
php codeigniter
add a comment |
I have designed a bilingual website initially loading in Arabic language by declaring a session variable 'language'.The index page load correctly ,but when i click the button to convert the language i'am getting the session variable undefined.please help me to fix this issue.
This below function load the home page.here am getting the session variable in the home page.
public function index(){
$_SESSION['page'] = 'Home';
if(empty( $_SESSION["language"])){
$_SESSION["language"] = "_ar";
}
$this->load->view('site'.$_SESSION["language"].'/index',$data);
}
In the home page when i click the language convert button it call the below controller function,but the session variable become undefined in this controller function.
When i open in i
public function lang_change_ar_to_eng() {
if ($_SESSION["language"] == "_en")
$_SESSION["language"] = "_ar";
else if($_SESSION["language"] == "_ar")
$_SESSION["language"] = "_en";
echo json_encode($_SESSION["language"]);
}
when i open in incognito window i got the session variables,i don't know what's the issue
php codeigniter
where is your code?
– Bhargav Chudasama
Nov 26 '18 at 7:32
Please post your code! Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.
– Ed Cottrell♦
Nov 26 '18 at 7:34
The above comment notwithstanding: your problem is almost certainly that you are not callingsession_start()
during every request. Really, that should be the first line of code that runs for each request.
– Ed Cottrell♦
Nov 26 '18 at 7:35
i have declared the session and a getting it in the home page of site,but become undefined in the controller when i click some link in the home page
– Jibin
Nov 26 '18 at 7:45
add a comment |
I have designed a bilingual website initially loading in Arabic language by declaring a session variable 'language'.The index page load correctly ,but when i click the button to convert the language i'am getting the session variable undefined.please help me to fix this issue.
This below function load the home page.here am getting the session variable in the home page.
public function index(){
$_SESSION['page'] = 'Home';
if(empty( $_SESSION["language"])){
$_SESSION["language"] = "_ar";
}
$this->load->view('site'.$_SESSION["language"].'/index',$data);
}
In the home page when i click the language convert button it call the below controller function,but the session variable become undefined in this controller function.
When i open in i
public function lang_change_ar_to_eng() {
if ($_SESSION["language"] == "_en")
$_SESSION["language"] = "_ar";
else if($_SESSION["language"] == "_ar")
$_SESSION["language"] = "_en";
echo json_encode($_SESSION["language"]);
}
when i open in incognito window i got the session variables,i don't know what's the issue
php codeigniter
I have designed a bilingual website initially loading in Arabic language by declaring a session variable 'language'.The index page load correctly ,but when i click the button to convert the language i'am getting the session variable undefined.please help me to fix this issue.
This below function load the home page.here am getting the session variable in the home page.
public function index(){
$_SESSION['page'] = 'Home';
if(empty( $_SESSION["language"])){
$_SESSION["language"] = "_ar";
}
$this->load->view('site'.$_SESSION["language"].'/index',$data);
}
In the home page when i click the language convert button it call the below controller function,but the session variable become undefined in this controller function.
When i open in i
public function lang_change_ar_to_eng() {
if ($_SESSION["language"] == "_en")
$_SESSION["language"] = "_ar";
else if($_SESSION["language"] == "_ar")
$_SESSION["language"] = "_en";
echo json_encode($_SESSION["language"]);
}
when i open in incognito window i got the session variables,i don't know what's the issue
php codeigniter
php codeigniter
edited Nov 26 '18 at 9:16
Jibin
asked Nov 26 '18 at 7:31
JibinJibin
52210
52210
where is your code?
– Bhargav Chudasama
Nov 26 '18 at 7:32
Please post your code! Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.
– Ed Cottrell♦
Nov 26 '18 at 7:34
The above comment notwithstanding: your problem is almost certainly that you are not callingsession_start()
during every request. Really, that should be the first line of code that runs for each request.
– Ed Cottrell♦
Nov 26 '18 at 7:35
i have declared the session and a getting it in the home page of site,but become undefined in the controller when i click some link in the home page
– Jibin
Nov 26 '18 at 7:45
add a comment |
where is your code?
– Bhargav Chudasama
Nov 26 '18 at 7:32
Please post your code! Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.
– Ed Cottrell♦
Nov 26 '18 at 7:34
The above comment notwithstanding: your problem is almost certainly that you are not callingsession_start()
during every request. Really, that should be the first line of code that runs for each request.
– Ed Cottrell♦
Nov 26 '18 at 7:35
i have declared the session and a getting it in the home page of site,but become undefined in the controller when i click some link in the home page
– Jibin
Nov 26 '18 at 7:45
where is your code?
– Bhargav Chudasama
Nov 26 '18 at 7:32
where is your code?
– Bhargav Chudasama
Nov 26 '18 at 7:32
Please post your code! Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.
– Ed Cottrell♦
Nov 26 '18 at 7:34
Please post your code! Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.
– Ed Cottrell♦
Nov 26 '18 at 7:34
The above comment notwithstanding: your problem is almost certainly that you are not calling
session_start()
during every request. Really, that should be the first line of code that runs for each request.– Ed Cottrell♦
Nov 26 '18 at 7:35
The above comment notwithstanding: your problem is almost certainly that you are not calling
session_start()
during every request. Really, that should be the first line of code that runs for each request.– Ed Cottrell♦
Nov 26 '18 at 7:35
i have declared the session and a getting it in the home page of site,but become undefined in the controller when i click some link in the home page
– Jibin
Nov 26 '18 at 7:45
i have declared the session and a getting it in the home page of site,but become undefined in the controller when i click some link in the home page
– Jibin
Nov 26 '18 at 7:45
add a comment |
3 Answers
3
active
oldest
votes
Most of Session errors are come from "Not declared session_start()"
You can check session is alive by below code.
echo session_id();
If that prints Null or empty string, that means session is closed.
i got a string..but session variable is undefined
– Jibin
Nov 26 '18 at 9:10
add a comment |
This issue can be resolved by using php version 7.2 on your server
add a comment |
Maybe you can show us some code. I think you have a wrong configuration.
This should be posted as a comment.
– Jeto
Nov 26 '18 at 7:53
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%2f53476488%2fphp-session-variable-become-undefined-when-click-to-another-link%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Most of Session errors are come from "Not declared session_start()"
You can check session is alive by below code.
echo session_id();
If that prints Null or empty string, that means session is closed.
i got a string..but session variable is undefined
– Jibin
Nov 26 '18 at 9:10
add a comment |
Most of Session errors are come from "Not declared session_start()"
You can check session is alive by below code.
echo session_id();
If that prints Null or empty string, that means session is closed.
i got a string..but session variable is undefined
– Jibin
Nov 26 '18 at 9:10
add a comment |
Most of Session errors are come from "Not declared session_start()"
You can check session is alive by below code.
echo session_id();
If that prints Null or empty string, that means session is closed.
Most of Session errors are come from "Not declared session_start()"
You can check session is alive by below code.
echo session_id();
If that prints Null or empty string, that means session is closed.
answered Nov 26 '18 at 8:34
devkingsejongdevkingsejong
563
563
i got a string..but session variable is undefined
– Jibin
Nov 26 '18 at 9:10
add a comment |
i got a string..but session variable is undefined
– Jibin
Nov 26 '18 at 9:10
i got a string..but session variable is undefined
– Jibin
Nov 26 '18 at 9:10
i got a string..but session variable is undefined
– Jibin
Nov 26 '18 at 9:10
add a comment |
This issue can be resolved by using php version 7.2 on your server
add a comment |
This issue can be resolved by using php version 7.2 on your server
add a comment |
This issue can be resolved by using php version 7.2 on your server
This issue can be resolved by using php version 7.2 on your server
answered Nov 26 '18 at 8:21
Parvej AlamParvej Alam
2167
2167
add a comment |
add a comment |
Maybe you can show us some code. I think you have a wrong configuration.
This should be posted as a comment.
– Jeto
Nov 26 '18 at 7:53
add a comment |
Maybe you can show us some code. I think you have a wrong configuration.
This should be posted as a comment.
– Jeto
Nov 26 '18 at 7:53
add a comment |
Maybe you can show us some code. I think you have a wrong configuration.
Maybe you can show us some code. I think you have a wrong configuration.
answered Nov 26 '18 at 7:39
JohnnyJohnny
5617
5617
This should be posted as a comment.
– Jeto
Nov 26 '18 at 7:53
add a comment |
This should be posted as a comment.
– Jeto
Nov 26 '18 at 7:53
This should be posted as a comment.
– Jeto
Nov 26 '18 at 7:53
This should be posted as a comment.
– Jeto
Nov 26 '18 at 7:53
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%2f53476488%2fphp-session-variable-become-undefined-when-click-to-another-link%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
where is your code?
– Bhargav Chudasama
Nov 26 '18 at 7:32
Please post your code! Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example.
– Ed Cottrell♦
Nov 26 '18 at 7:34
The above comment notwithstanding: your problem is almost certainly that you are not calling
session_start()
during every request. Really, that should be the first line of code that runs for each request.– Ed Cottrell♦
Nov 26 '18 at 7:35
i have declared the session and a getting it in the home page of site,but become undefined in the controller when i click some link in the home page
– Jibin
Nov 26 '18 at 7:45