php Session variable become undefined when click to another link












-1















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










share|improve this question

























  • 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
















-1















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










share|improve this question

























  • 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














-1












-1








-1








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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



















  • 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

















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












3 Answers
3






active

oldest

votes


















1














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.






share|improve this answer
























  • i got a string..but session variable is undefined

    – Jibin
    Nov 26 '18 at 9:10



















0














This issue can be resolved by using php version 7.2 on your server






share|improve this answer































    -1














    Maybe you can show us some code. I think you have a wrong configuration.






    share|improve this answer
























    • This should be posted as a comment.

      – Jeto
      Nov 26 '18 at 7:53











    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer
























    • i got a string..but session variable is undefined

      – Jibin
      Nov 26 '18 at 9:10
















    1














    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.






    share|improve this answer
























    • i got a string..but session variable is undefined

      – Jibin
      Nov 26 '18 at 9:10














    1












    1








    1







    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.






    share|improve this answer













    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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



















    • 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













    0














    This issue can be resolved by using php version 7.2 on your server






    share|improve this answer




























      0














      This issue can be resolved by using php version 7.2 on your server






      share|improve this answer


























        0












        0








        0







        This issue can be resolved by using php version 7.2 on your server






        share|improve this answer













        This issue can be resolved by using php version 7.2 on your server







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 8:21









        Parvej AlamParvej Alam

        2167




        2167























            -1














            Maybe you can show us some code. I think you have a wrong configuration.






            share|improve this answer
























            • This should be posted as a comment.

              – Jeto
              Nov 26 '18 at 7:53
















            -1














            Maybe you can show us some code. I think you have a wrong configuration.






            share|improve this answer
























            • This should be posted as a comment.

              – Jeto
              Nov 26 '18 at 7:53














            -1












            -1








            -1







            Maybe you can show us some code. I think you have a wrong configuration.






            share|improve this answer













            Maybe you can show us some code. I think you have a wrong configuration.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 26 '18 at 7:39









            JohnnyJohnny

            5617




            5617













            • 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





            This should be posted as a comment.

            – Jeto
            Nov 26 '18 at 7:53


















            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks