| Author |
Message |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2958 Location: Earth
|
Posted: Thu Jan 24, 2008 8:18 am Post subject: checking a cookie in PHP |
|
|
I have a cookie that is being set in javascript
| Code: | function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
setCookie("shoot","true",1) |
And on another page i'm trying to check if it exists
| Code: | if (isset($_COOKIE['shoot'])) {
$_SESSION['action'] = "reward";
}
echo "<br />Session: ".$_SESSION['action'];
echo "<br />Cookie: ".$_COOKIE['shoot']; |
The echos give
Session:
Cookie:
Firefox shows that the cookie exists, so why doesn't it work?
Is there something else i need to do?
The other cookies i check using the same code work fine, just not this one _________________ Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG |
|
| Back to top |
|
| |
LP-SolidRaven Dictator of the Dump

Joined: 06 Jun 2004 Posts: 7015 Location: The cheese is made out of moon
|
Posted: Thu Jan 24, 2008 2:21 pm Post subject: |
|
|
I'm not so sure you can always access cookies set in javascript at the server side. _________________
| Quote: |
<bart416> I just realized something
<bart416> we celebrate the fact that this piece of rock made one rotation around a glowing ball of plasma that is kept together due to its own gravity well
<njsg> HAPPY NEW YEAR
<Easter> ^^
|
|
|
| Back to top |
|
| |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2958 Location: Earth
|
Posted: Thu Jan 24, 2008 2:24 pm Post subject: |
|
|
ok, is there another way of doing the same thing. I'm told i can't set a session variable which is what i originally wanted to do, and was recommended to use cookies but that doesn't seem to work.
What i'm trying to do is make it so that you have to play the game before getting the prize _________________ Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG |
|
| Back to top |
|
| |
LP-SolidRaven Dictator of the Dump

Joined: 06 Jun 2004 Posts: 7015 Location: The cheese is made out of moon
|
Posted: Thu Jan 24, 2008 2:52 pm Post subject: |
|
|
Session variables are stored server side. What you do have available is the php session id.
With a couple of masked http requests in your javascript you could interact with the server and change the session values. _________________
| Quote: |
<bart416> I just realized something
<bart416> we celebrate the fact that this piece of rock made one rotation around a glowing ball of plasma that is kept together due to its own gravity well
<njsg> HAPPY NEW YEAR
<Easter> ^^
|
|
|
| Back to top |
|
| |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2958 Location: Earth
|
|
| Back to top |
|
| |
nooc Master Poster

Joined: 10 Aug 2005 Posts: 215
|
Posted: Fri Jan 25, 2008 1:02 am Post subject: |
|
|
You should be able to set a cookie like you're doing.
Make sure to add a proper domain/path entry if your cookie jumps subdomains/paths. |
|
| Back to top |
|
| |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2958 Location: Earth
|
|
| Back to top |
|
| |
|
|
|