Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 29th, 2003, 06:24 PM
Registered User
 
Join Date: Aug 2003
Location: Camas, WA, .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shabboleth
Default Cookies

Hello All,

I am trying to use cookies to get my application to recognize returning users. After logging in I want to set a cookie using the following line of code:

setcookie("username", $username, time() + 31536000);

But it doesn't seem to be working. I have tried to access the cookie using $_COOKIE['username'],and $HTTP_COOKIE_VARS['username'], and I always get a null value.

I have also tried:

if(isset($username))

and it always comes up negative.

Can anyone tell me what I am doing wrong?

Glen
Reply With Quote
  #2 (permalink)  
Old December 29th, 2003, 06:56 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Okay, be a little more explicit -- Are you setting the cookie on the same page that you're checking it's existence on?

A cookie variable won't exist in $_COOKIE until you load another page under the same path for which the cookie is valid.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #3 (permalink)  
Old December 29th, 2003, 06:57 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also, you should check the return value of setcookie(). It should return TRUE if it ran successfully. Note that this doesn't indicate whether a user accepts the cookie -- TRUE here just means that setcookie was able to properly generate and send the proper HTTP header.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #4 (permalink)  
Old December 30th, 2003, 10:32 AM
Registered User
 
Join Date: Aug 2003
Location: Camas, WA, .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to shabboleth
Default

OK, I checked the return value of setcookie() and it was setting fine. My problem was something else.

I appreciate everyone's help getting past these basic mistakes.

Glen

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cookies hastikeyvan Classic ASP Professional 5 May 29th, 2006 07:36 AM
Should I use cookies?? Help Tee88 Classic ASP Basics 3 January 21st, 2005 12:33 AM
Cookies cjo ASP.NET 1.0 and 1.1 Basics 1 November 8th, 2003 02:38 PM
Help!About Cookies jelsen ASP.NET 1.0 and 1.1 Basics 2 September 9th, 2003 08:36 AM



All times are GMT -4. The time now is 07:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.