Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie or Session help

Status
Not open for further replies.

okiiyama

IS-IT--Management
Joined
Jan 3, 2003
Messages
269
Location
US
Im sure this is a pretty basic question....but I need help with either cookies or using a session variable.

I need to have a variable that stores the user's Customer Id throughout my website. I've looked at examples of cookies and Session stuff, but I just don't get it. It seems easy enough, so I think Im missing something extremely basic. I am trying to set up a shopping cart, and right now because my variables are limited to the page and not the site, almost every other page the user would have to type in at least their email address so that I can do a query that would retreive their CustId from the database.

Between cookies and session, i don't have a clue as to which I should use or which is more appropriate. I just want to store a value once and retrieve that value from time to time while that user is on my site.

Ive tried to use cookies a little, and mostly, I get an error about "Header..blah.blah.."

I would love any help that I can, just assume that I have no clue what Im doing with php. =)

THank You
 
session are a little more secure and very simple to use. read the manual for more help and explanations
Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
A cookie sets a single value for storage on a user's web client. That single value can be concatenated multiple values, but it is a single value. There are also limits to how much you can store in a cookie.

When you use a session variable in PHP, PHP automatically generates a random session ID and stores that value on the client in a cookie named, by default, PHPSESSID.

PHP stores the actual session values, by default, on the filesystem of the server. Each user's session values are stored in a separate file, each file named sess_<the session id previously generated>.

PHP can then take the value returned by the client in the PHPSESSID cookie and use that value to retrieve the session values from the server's filesystem. Like a database, with the indeces stored on individual client machines.

Since the values are stored on the filesystem, you can store a lot more in a session than you can in a cookie: arrays, objects, etc.


The &quot;Unable to set header...Information already sent&quot; error is described in my FAQ on debugging PHP. FAQ434-2999

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top