How to custom cookie path from different link (local and server)Cannot delete cookies that were set in JavaScript on the serverHow to get the value from the GET parameters?How do I set/unset a cookie with jQuery?How do I get a YouTube video thumbnail from the YouTube API?How can I open a URL in Android's web browser from my application?Local Storage vs CookiesCannot retrieve cookies in codeigniterWhat is the difference between localStorage, sessionStorage, session and cookies?disable codeigniter session cookie for php soap serverHow to change base_url() path from localhost to hosted site?

Wifi dongle speed is slower than advertised

Can ADFS connect to other SSO services?

How long would it take to cross the Channel in 1890's?

Should I prioritize my 401(k) over my student loans?

Why is C++ initial allocation so much larger than C's?

Has there been any indication at all that further negotiation between the UK and EU is possible?

What are the penalties for overstaying in USA?

How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?

What is the origin of Scooby-Doo's name?

Can the negators "jamais, rien, personne, plus, ni, aucun" be used in a single sentence?

Why aren't cotton tents more popular?

Is there a maximum distance from a planet that a moon can orbit?

What's currently blocking the construction of the wall between Mexico and the US?

What reason would an alien civilization have for building a Dyson Sphere (or Swarm) if cheap Nuclear fusion is available?

Interaction between Leyline of Anticipation and Teferi, Time Raveler

Can White Castle?

Suggested order for Amazon Prime Doctor Who series

Require advice on power conservation for backpacking trip

Is there a way to split the metadata to custom folders?

Impossible darts scores

Trainee keeps missing deadlines for independent learning

Why doesn't a marching band have strings?

STM Microcontroller burns every time

Unusual mail headers, evidence of an attempted attack. Have I been pwned?



How to custom cookie path from different link (local and server)


Cannot delete cookies that were set in JavaScript on the serverHow to get the value from the GET parameters?How do I set/unset a cookie with jQuery?How do I get a YouTube video thumbnail from the YouTube API?How can I open a URL in Android's web browser from my application?Local Storage vs CookiesCannot retrieve cookies in codeigniterWhat is the difference between localStorage, sessionStorage, session and cookies?disable codeigniter session cookie for php soap serverHow to change base_url() path from localhost to hosted site?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I have some trouble with setting up a correct Cookie path. What do i want to achieve?



  1. I have a project that runs on my localhost server, with a path http://localhost/project_folder/Controller/function


  2. I can set the Cookie path using the mentioned relative path /project_folder/Controller/function and it works


  3. But when the project runs on another server, where the structure is a bit different, i.e.: http://localhost/project part is replaced by http://www.example.com/Controller, then the trouble begins


I am using CodeIgniter framework.



To achieve the metioned i have tried using the base_url() function CodeIgniter provides and if i change the site path in the configuration it works on the second server but does not work on the local one and vice-versa ...



How should i properly handle the Cookie path in this situation?




EDITED:



It's a simple Cookie set (i'm using a Custom cookie function in JavaScript and i'm setting the Cookie via JavaScript):



createCookie('filter_products', params, '1', '<?php echo base_url('Controller/function'); ?>');


The problem is, that the base_url() function returns the path below like i said before:



http://localhost/project_folder/Controller/function



But on the server the localhost/project_folder/ part is replaced by the domain name, so how can i create the Cookie path dynamically?










share|improve this question
























  • Can you provide some code examples of what you've already tried? Put us more in the context.

    – CodiMech25
    Mar 25 at 14:33











  • i have updated my question please see it again, @CodiMech25

    – Yosafat Ksatria
    Mar 26 at 3:36


















-1















I have some trouble with setting up a correct Cookie path. What do i want to achieve?



  1. I have a project that runs on my localhost server, with a path http://localhost/project_folder/Controller/function


  2. I can set the Cookie path using the mentioned relative path /project_folder/Controller/function and it works


  3. But when the project runs on another server, where the structure is a bit different, i.e.: http://localhost/project part is replaced by http://www.example.com/Controller, then the trouble begins


I am using CodeIgniter framework.



To achieve the metioned i have tried using the base_url() function CodeIgniter provides and if i change the site path in the configuration it works on the second server but does not work on the local one and vice-versa ...



How should i properly handle the Cookie path in this situation?




EDITED:



It's a simple Cookie set (i'm using a Custom cookie function in JavaScript and i'm setting the Cookie via JavaScript):



createCookie('filter_products', params, '1', '<?php echo base_url('Controller/function'); ?>');


The problem is, that the base_url() function returns the path below like i said before:



http://localhost/project_folder/Controller/function



But on the server the localhost/project_folder/ part is replaced by the domain name, so how can i create the Cookie path dynamically?










share|improve this question
























  • Can you provide some code examples of what you've already tried? Put us more in the context.

    – CodiMech25
    Mar 25 at 14:33











  • i have updated my question please see it again, @CodiMech25

    – Yosafat Ksatria
    Mar 26 at 3:36














-1












-1








-1








I have some trouble with setting up a correct Cookie path. What do i want to achieve?



  1. I have a project that runs on my localhost server, with a path http://localhost/project_folder/Controller/function


  2. I can set the Cookie path using the mentioned relative path /project_folder/Controller/function and it works


  3. But when the project runs on another server, where the structure is a bit different, i.e.: http://localhost/project part is replaced by http://www.example.com/Controller, then the trouble begins


I am using CodeIgniter framework.



To achieve the metioned i have tried using the base_url() function CodeIgniter provides and if i change the site path in the configuration it works on the second server but does not work on the local one and vice-versa ...



How should i properly handle the Cookie path in this situation?




EDITED:



It's a simple Cookie set (i'm using a Custom cookie function in JavaScript and i'm setting the Cookie via JavaScript):



createCookie('filter_products', params, '1', '<?php echo base_url('Controller/function'); ?>');


The problem is, that the base_url() function returns the path below like i said before:



http://localhost/project_folder/Controller/function



But on the server the localhost/project_folder/ part is replaced by the domain name, so how can i create the Cookie path dynamically?










share|improve this question
















I have some trouble with setting up a correct Cookie path. What do i want to achieve?



  1. I have a project that runs on my localhost server, with a path http://localhost/project_folder/Controller/function


  2. I can set the Cookie path using the mentioned relative path /project_folder/Controller/function and it works


  3. But when the project runs on another server, where the structure is a bit different, i.e.: http://localhost/project part is replaced by http://www.example.com/Controller, then the trouble begins


I am using CodeIgniter framework.



To achieve the metioned i have tried using the base_url() function CodeIgniter provides and if i change the site path in the configuration it works on the second server but does not work on the local one and vice-versa ...



How should i properly handle the Cookie path in this situation?




EDITED:



It's a simple Cookie set (i'm using a Custom cookie function in JavaScript and i'm setting the Cookie via JavaScript):



createCookie('filter_products', params, '1', '<?php echo base_url('Controller/function'); ?>');


The problem is, that the base_url() function returns the path below like i said before:



http://localhost/project_folder/Controller/function



But on the server the localhost/project_folder/ part is replaced by the domain name, so how can i create the Cookie path dynamically?







php codeigniter url cookies






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 6:24









CodiMech25

4402 silver badges9 bronze badges




4402 silver badges9 bronze badges










asked Mar 25 at 9:40









Yosafat KsatriaYosafat Ksatria

369 bronze badges




369 bronze badges












  • Can you provide some code examples of what you've already tried? Put us more in the context.

    – CodiMech25
    Mar 25 at 14:33











  • i have updated my question please see it again, @CodiMech25

    – Yosafat Ksatria
    Mar 26 at 3:36


















  • Can you provide some code examples of what you've already tried? Put us more in the context.

    – CodiMech25
    Mar 25 at 14:33











  • i have updated my question please see it again, @CodiMech25

    – Yosafat Ksatria
    Mar 26 at 3:36

















Can you provide some code examples of what you've already tried? Put us more in the context.

– CodiMech25
Mar 25 at 14:33





Can you provide some code examples of what you've already tried? Put us more in the context.

– CodiMech25
Mar 25 at 14:33













i have updated my question please see it again, @CodiMech25

– Yosafat Ksatria
Mar 26 at 3:36






i have updated my question please see it again, @CodiMech25

– Yosafat Ksatria
Mar 26 at 3:36













1 Answer
1






active

oldest

votes


















0














The first thing that comes to my mind is, that you should avoid setting Cookies via JavaScript if it is possible and use the CodeIgniter built-in helper or the native PHP functions.



To your question:



For dynamic decision on which server you are, you can use the PHP super-global $_SERVER value which is accessible from anywhere in your code. The SERVER_NAME field contains the actual name of the host, so you can use something like:



<?php

if (isset($_SERVER, $_SERVER['SERVER_NAME']))
if ($_SERVER['SERVER_NAME'] === 'localhost')
// set base path to localhost/project_folder
else
// set base path to www.example.com <- MORE SECURE
// or, set base path to $_SERVER['SERVER_NAME'] <- INSECURE (any server could be written to the config)







share|improve this answer

























    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%2f55334910%2fhow-to-custom-cookie-path-from-different-link-local-and-server%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    The first thing that comes to my mind is, that you should avoid setting Cookies via JavaScript if it is possible and use the CodeIgniter built-in helper or the native PHP functions.



    To your question:



    For dynamic decision on which server you are, you can use the PHP super-global $_SERVER value which is accessible from anywhere in your code. The SERVER_NAME field contains the actual name of the host, so you can use something like:



    <?php

    if (isset($_SERVER, $_SERVER['SERVER_NAME']))
    if ($_SERVER['SERVER_NAME'] === 'localhost')
    // set base path to localhost/project_folder
    else
    // set base path to www.example.com <- MORE SECURE
    // or, set base path to $_SERVER['SERVER_NAME'] <- INSECURE (any server could be written to the config)







    share|improve this answer



























      0














      The first thing that comes to my mind is, that you should avoid setting Cookies via JavaScript if it is possible and use the CodeIgniter built-in helper or the native PHP functions.



      To your question:



      For dynamic decision on which server you are, you can use the PHP super-global $_SERVER value which is accessible from anywhere in your code. The SERVER_NAME field contains the actual name of the host, so you can use something like:



      <?php

      if (isset($_SERVER, $_SERVER['SERVER_NAME']))
      if ($_SERVER['SERVER_NAME'] === 'localhost')
      // set base path to localhost/project_folder
      else
      // set base path to www.example.com <- MORE SECURE
      // or, set base path to $_SERVER['SERVER_NAME'] <- INSECURE (any server could be written to the config)







      share|improve this answer

























        0












        0








        0







        The first thing that comes to my mind is, that you should avoid setting Cookies via JavaScript if it is possible and use the CodeIgniter built-in helper or the native PHP functions.



        To your question:



        For dynamic decision on which server you are, you can use the PHP super-global $_SERVER value which is accessible from anywhere in your code. The SERVER_NAME field contains the actual name of the host, so you can use something like:



        <?php

        if (isset($_SERVER, $_SERVER['SERVER_NAME']))
        if ($_SERVER['SERVER_NAME'] === 'localhost')
        // set base path to localhost/project_folder
        else
        // set base path to www.example.com <- MORE SECURE
        // or, set base path to $_SERVER['SERVER_NAME'] <- INSECURE (any server could be written to the config)







        share|improve this answer













        The first thing that comes to my mind is, that you should avoid setting Cookies via JavaScript if it is possible and use the CodeIgniter built-in helper or the native PHP functions.



        To your question:



        For dynamic decision on which server you are, you can use the PHP super-global $_SERVER value which is accessible from anywhere in your code. The SERVER_NAME field contains the actual name of the host, so you can use something like:



        <?php

        if (isset($_SERVER, $_SERVER['SERVER_NAME']))
        if ($_SERVER['SERVER_NAME'] === 'localhost')
        // set base path to localhost/project_folder
        else
        // set base path to www.example.com <- MORE SECURE
        // or, set base path to $_SERVER['SERVER_NAME'] <- INSECURE (any server could be written to the config)








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 5:37









        CodiMech25CodiMech25

        4402 silver badges9 bronze badges




        4402 silver badges9 bronze badges





























            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%2f55334910%2fhow-to-custom-cookie-path-from-different-link-local-and-server%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현