Cookies
Moderator: General Moderators
Cookies
Hi guys,
I am developing an application that uses cookies but for some hours I have been getting an error. I set the cookie by using a .swf file which calls a JavaScript function that sets the Cookie. Then I try to get it by using Php nd this is the point when I do not have it. When I check the browser properties it the cookie is there. When I call it from the index page og the portal it works too but when I try to call it by using a Php script placed in another file different from the index one I can't get it. I think that this may be caused by the path because when I check the browser I see the root(index) path. My question is how to solve the problem with the path(If this is problem). WhenI use the $GLOBALS var I do not have it either.
I am developing an application that uses cookies but for some hours I have been getting an error. I set the cookie by using a .swf file which calls a JavaScript function that sets the Cookie. Then I try to get it by using Php nd this is the point when I do not have it. When I check the browser properties it the cookie is there. When I call it from the index page og the portal it works too but when I try to call it by using a Php script placed in another file different from the index one I can't get it. I think that this may be caused by the path because when I check the browser I see the root(index) path. My question is how to solve the problem with the path(If this is problem). WhenI use the $GLOBALS var I do not have it either.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
I'd be willing to bet you're not using the $_COOKIE superglobal:
http://www.php.net/manual/en/reserved.v ... es.cookies
If you try that and still have an issue, post your javascript and php code (in appropriate bbcode tags).
http://www.php.net/manual/en/reserved.v ... es.cookies
If you try that and still have an issue, post your javascript and php code (in appropriate bbcode tags).
Cookies
But I do. I use it. I am giving you the pseudo code because the real one is a very long one.
In Flash:
Simple HTML with a href="javascript:Function that sets the cookie"(As far as I have been testing until now it works)
JavaScript:
Here is the function called from the href above
function ...(id) {
Do some validation
Gets the id
Sets the cookie}//I used another JavaScript function to check whther the cookie is set and it is
Php:
//First do some validation
use
$somevar = $_COOKIE['the name of the cookie'];
//Validation does not make any problems
//I tried to make it wotk without them
In Flash:
Simple HTML with a href="javascript:Function that sets the cookie"(As far as I have been testing until now it works)
JavaScript:
Here is the function called from the href above
function ...(id) {
Do some validation
Gets the id
Sets the cookie}//I used another JavaScript function to check whther the cookie is set and it is
Php:
//First do some validation
use
$somevar = $_COOKIE['the name of the cookie'];
//Validation does not make any problems
//I tried to make it wotk without them
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Cookies
feyd | Please use [/syntax]
This is a short one but only this matters with the very creation of the cookie. As I have already pointed the problem is that I do not get the cookie in the Php.[/quote]
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I will post only the core of it:
[syntax="javascript"] document.cookie = name + "=" +"; expires=Thu, 01-Jan-1970 00:00:01 GMT";
var when = new Date();
when.setTime(when.getTime() + 24 * 60 * 60 * 1000);
// 24 hours from now
when.setFullYear(when.getFullYear() + 1);
// One year from now
document.cookie=name+"="+escape(value)+
";expires="+when.toGMTString();Code: Select all
$thevar = $_COOKIE['tmsms'];feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]Cookies
Suggestions? I have tried by using setcookie() in the root file and it works but I want to know where the problem comes from.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:4. All users of any level are restricted to bumping (as defined here) any given thread within twenty-four (24) hours of its last post. Non-trivial posts are not considered bumping. A bump post found in violation will be deleted, and you may or may not receive a warning. Persons bumping excessively be considered as spammers and dealt with accordingly.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Cookies`
Unfortunately I have tried this too but it does not work.
Let me try to explain better if I could
I have an index.php file
in this file I include another file that uses some conditions and then by using Ajax on the html page(It is simple and has nothing to do with cookies that's why I have posted it) I display the cookie by calling the .php file that contains the Php code. The scripts breaks at the point of the displaying.
Let me try to explain better if I could
I have an index.php file
in this file I include another file that uses some conditions and then by using Ajax on the html page(It is simple and has nothing to do with cookies that's why I have posted it) I display the cookie by calling the .php file that contains the Php code. The scripts breaks at the point of the displaying.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
try:
Code: Select all
var when = new Date();
when.setTime(when.getTime() + 24 * 60 * 60 * 1000); // 24 hours from now
when.setFullYear(when.getFullYear() + 1); // a year after that? I guess, it's your code.
document.cookie = name + "=" + escape(value) + "; expires="+ when.toGMTString() + "; path=/";- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA