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;
I have some trouble with setting up a correct Cookie path. What do i want to achieve?
I have a project that runs on my localhost server, with a path
http://localhost/project_folder/Controller/function
I can set the Cookie path using the mentioned relative path
/project_folder/Controller/function
and it worksBut when the project runs on another server, where the structure is a bit different, i.e.:
http://localhost/project
part is replaced byhttp://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
add a comment |
I have some trouble with setting up a correct Cookie path. What do i want to achieve?
I have a project that runs on my localhost server, with a path
http://localhost/project_folder/Controller/function
I can set the Cookie path using the mentioned relative path
/project_folder/Controller/function
and it worksBut when the project runs on another server, where the structure is a bit different, i.e.:
http://localhost/project
part is replaced byhttp://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
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
add a comment |
I have some trouble with setting up a correct Cookie path. What do i want to achieve?
I have a project that runs on my localhost server, with a path
http://localhost/project_folder/Controller/function
I can set the Cookie path using the mentioned relative path
/project_folder/Controller/function
and it worksBut when the project runs on another server, where the structure is a bit different, i.e.:
http://localhost/project
part is replaced byhttp://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
I have some trouble with setting up a correct Cookie path. What do i want to achieve?
I have a project that runs on my localhost server, with a path
http://localhost/project_folder/Controller/function
I can set the Cookie path using the mentioned relative path
/project_folder/Controller/function
and it worksBut when the project runs on another server, where the structure is a bit different, i.e.:
http://localhost/project
part is replaced byhttp://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
php codeigniter url cookies
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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)
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%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
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)
add a comment |
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)
add a comment |
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)
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)
answered Mar 26 at 5:37
CodiMech25CodiMech25
4402 silver badges9 bronze badges
4402 silver badges9 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%2f55334910%2fhow-to-custom-cookie-path-from-different-link-local-and-server%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
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