Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

checking a cookie in PHP

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2958
Location: Earth

PostPosted: Thu Jan 24, 2008 8:18 am    Post subject: checking a cookie in PHP Reply with quote

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

PostPosted: Thu Jan 24, 2008 2:21 pm    Post subject: Reply with quote

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

PostPosted: Thu Jan 24, 2008 2:24 pm    Post subject: Reply with quote

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

PostPosted: Thu Jan 24, 2008 2:52 pm    Post subject: Reply with quote

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

PostPosted: Thu Jan 24, 2008 3:04 pm    Post subject: Reply with quote

how would i go about doing that? i know nothing of javascript
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
nooc
Master Poster


Joined: 10 Aug 2005
Posts: 215


PostPosted: Fri Jan 25, 2008 1:02 am    Post subject: Reply with quote

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

PostPosted: Fri Jan 25, 2008 2:13 am    Post subject: Reply with quote

the cookie is only used on this one page
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com