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

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript