Printer Friendly Version Print this thread
Email this thread to a friend eMail this thread to a friend
Featured Web Site Template

Hundreds More at Free Site Templates.com!

Web Site Partners
Sponsored Links
Jet City Software
 
Whos Here ?
There are 0 guests and 1 members in the forums right now.
Reflects user activity within the last 5 minutes
Moderator(s): Prowler, jcokos
Member Message

goldrush
Joined: Aug 17, 2005
# Posts: 3

View the profile for goldrush Send goldrush a private message

Posted: 2006-Jan-18 04:47
Edit Message Delete Message Reply to this message

Hey

Im making a shopping cart for a jewellery website and im having a bit of trouble with cookies. Oh and by the way im using php.

Firstly ive got this code which creates the cookie with a generated id.


Code: [copy]





And then after the customer orders ive got this code which deletes the cookie so that the user wont have the same cart after theyve ordered.


Code: [copy]





But even after theyve ordered and the code above has run, for some reason the user still has the same cookie with the same id. :pinch:

Please if you see any errors in my code above or have any sugestions please reply!



dirty_shame
Joined: Aug 28, 2005
# Posts: 191

View the profile for dirty_shame Send dirty_shame a private message

Posted: 2006-Jan-18 07:08
Edit Message Delete Message Reply to this message

You now have to include your domain name in cookies.



Code: [copy]





[ Message was edited by: JimBot 01/21/2006 12:18 pm ... Reason: Fixed Code Example. ]





dudibob
Joined: Oct 13, 2005
# Posts: 1462

View the profile for dudibob Send dudibob a private message

Posted: 2006-Jan-18 11:43
Edit Message Delete Message Reply to this message

woah, looks complex sad



dirty_shame
Joined: Aug 28, 2005
# Posts: 191

View the profile for dirty_shame Send dirty_shame a private message

Posted: 2006-Jan-21 05:47
Edit Message Delete Message Reply to this message

Nah. It's pretty straightforward. You don't have to use the get_unique_id function I quoted at the top. It's just the way I create 'em. No variables passed.

The only important addition is the slash (to indicate the server domain default directory) and the domain name itself in the SetCookie function.

Otherwise, most all modern browsers will reject a cookie (under even standard security settings) that does not declare in it's http header that it is being created from the same URL that the browser is currently viewing.



IanK
Joined: Dec 07, 2003
# Posts: 90

View the profile for IanK Send IanK a private message

Posted: 2006-Feb-04 09:36
Edit Message Delete Message Reply to this message

Browsers reject cookies from domains outside of the one you are browsing.

In PHP if you set a cookie without the domain specified every browser I've ever seen will accept it.

As illustrated in this thread by the fact that the user is getting the cookie. That was never the problem smile

The problem, apparently, is that the cookie is not getting deleted. Unfortunately as far as I can see the code is fine, it should be working.



dirty_shame
Joined: Aug 28, 2005
# Posts: 191

View the profile for dirty_shame Send dirty_shame a private message

Posted: 2006-Feb-05 00:42
Edit Message Delete Message Reply to this message

Because, IanK, you can't delete a cookie with a Global session() call...It just deletes the PHP session on the server, not the cookie in the visitors browser. You have to basically "reset" the cookie to nothing and pre-date it to delete it on their end.

Saying you've never failed to set a cookie WITHOUT specifying the domain is like saying you've never been stuck in the mud without ever having left the highway. At any rate, why risk losing a customer when it is such an incredibly easy thing to do anyway?

[ Message was edited by: dirty_shame 02/04/2006 05:21 pm ]





iririr
Joined: Aug 15, 2008
# Posts: 1

View the profile for iririr Send iririr a private message

Posted: 2008-Aug-15 17:01
Edit Message Delete Message Reply to this message

dirty_shame, thanks for your insistence on setting the domain in the cookie. My cookie was acting inconsistently across my site, and it was because no domain was being set. It's a real dirty shame that not even php.net encourages you to do that.


You are not permitted to post messages in this forum or topic, because of one or more of the following reasons:
  1. You have not yet logged in, or registered properly as a member
  2. You are a member, but no longer have posting rights.
  3. This is a private forum, for which you do not have permissions.

If you are a recent member, it's possible that you simply have not yet confirmed your account. Please check your email for a message entitled 'JimWorld Forums: Confirm Your Account' and follow the instructions contained within.

If you cannot find this message, click here to Re-Send it.

If you are still experiencing problem, please read the Login Assistance Article for some advice on what may be causing your login not to work properly.

Switch to Advanced Editor and ... Create a New Topic or Reply to this Thread

New posts Forum is locked
© 1995  ·  iWeb, Inc  ·  DBA JimWorld Productions