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

 
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: 2963
Location: Earth

PostPosted: Mon Feb 04, 2008 11:20 am    Post subject: checking a cookie Reply with quote

I'm using this to check to see if i'm logged in
Code:
if($_COOKIE['mttcg']['u'] != 'Desbrina') {
      die("Please log in");
   }


Which works fine for me

I'm trying to add a second person to the check. I tried changing it but it always says please log in. Whats the correct way of checking if its either me logged in (Desbrina) or the other admin (Lunix)
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
ClickFanatic
Est. 2005


Joined: 18 Jan 2005
Posts: 3877
Location: A particular geographic area

PostPosted: Mon Feb 04, 2008 3:58 pm    Post subject: Reply with quote

First of all, it is not secure to rely solely on cookies to check the login status of a visitor. A malicious visitor could set their cookie to contain the required value and gain certain permissions you probably do not want to give away.

To find out what is causing your problem, I would recommend taking a look at the way the cookies are set. Make sure that the cookie is set properly when the required conditions are met.
_________________
Captain Jell-O Buster from the Future
[img]http://feeds.feedburner.com/sparepencil.1.gif[/img]
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2963
Location: Earth

PostPosted: Wed Feb 06, 2008 4:09 am    Post subject: Reply with quote

I've found out it works fine if i have it like this
Code:
if($_COOKIE['mttcg']['u'] == 'Desbrina' || $_COOKIE['mttcg']['u'] == 'Lunix') {
   } else {
      die("Please log in");
   }

but not if i have it the way i had it originally, which i dont understand

Quote:
First of all, it is not secure to rely solely on cookies to check the login status of a visitor. A malicious visitor could set their cookie to contain the required value and gain certain permissions you probably do not want to give away.


Whats another good way to use as well as cookies?
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4619
Location: Down Under

PostPosted: Wed Feb 06, 2008 5:22 am    Post subject: Reply with quote

Quote:
but not if i have it the way i had it originally, which i dont understand

Probably messed up with not this nor this syntax, it can be a bit tricky.

Quote:
Whats another good way to use as well as cookies?

Not "as well as", cookies should at most be to resume a session, a la "remember me", and backed with a changing hash that expires and/or takes into account user agent and IP. Sessions are the recommended method, www.php.net/sessions
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2963
Location: Earth

PostPosted: Wed Feb 06, 2008 6:06 am    Post subject: Reply with quote

my original coding for it was

Code:
if($_COOKIE['mttcg']['u'] != 'Desbrina' || $_COOKIE['mttcg']['u'] != 'Lunix') {
      die("Please log in");
   }


I used to use sessions, but didn't like the fact they expired when you closed the browser, and someone recommended using cookies instead of sessions
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Back to top
 
krt
...


Joined: 11 Jan 2005
Posts: 4619
Location: Down Under

PostPosted: Wed Feb 06, 2008 6:56 am    Post subject: Reply with quote

Your conditional would only accept a string which is both Desbrina and Lunix (which is not possible).

Regarding sessions and expiry times, read what I said again. I took into account expiration of sessions. Basically, sessions are used primarily, but a session can be "resumed" with a cookie. Note that the cookie must be hard to fake, and must have some protection against those that get access to the contents to the cookie, hence the IP and user agent used in hash computation and expiry times. A cookie with username=x doesn't come close to the cut.
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