Please help me,save and get cookies by Javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
pluspluscee
Forum Newbie
Posts: 1
Joined: Sun Dec 03, 2006 7:04 am

Please help me,save and get cookies by Javascript

Post by pluspluscee »

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]


Howdy php experts and specialists,

I have a problem in the thing that i want to save a pair of value to cookie by Javascript and then I get it up and assign to a variable in php code


[syntax="javascript"]<script language ="javascript">
function setCook(msValue) // msValue is a variable that has a certain value
{
var ExpireDate = new Date ();
ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));

document.cookies = bien + "=" + msValue + 
((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); 
}

</script> 
[/syntax]

Code: Select all

<?php

// assign the value which i get it up from cookie to $gay in php 

$gay = $_COOKIE['bien']; // is that right???Here i want to get the "msValue" value which I had saved it to cookie
But the $gay does not have the value I want (the msValue)

Please help me asap.thks much


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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Where are the values behind "bien" and "expiredays" coming from; more importantly, what are they?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

In the Javascript, "bien" is a variable but did you mean?

Code: Select all

document.cookies = "bien=" + msValue +
What's expiredays set to?

After setting the cookie how are you calling the PHP script?

Off Topic: You should escape() the cookies value too.
Post Reply