How can I keep data for users that are not logged in yet

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am building a website and I want to allow users to do certain things  
without logging in. I would like to allow them to keep track of certain  
items, by adding them to a list.

Like if they are viewing multiple job listings in Houston, they can add each  
job they care about to a list and when they are done looking at all the  
jobs, they can view the list of say, 10 jobs. They can print the list or  
email the list to themselves or someone else.

1st, what is the best way to track this user? IP address? I can have  
multiple guest users online at any given time. I don't want to put them in  
the database.

2nd, What is the best way to do this. Session variables? A session array?

What kind of data structure can I setup?

$visitorId = the ip address i get from $_SERVER['REMOTE_ADDR'] or should I  
just use a session_id that php provides? Is that good enough?

$userLevel = "Guest"
$time = time();
$rememberItem = array();

Every time a visitor checks the remember me checkbox next to a job, I will  
add that jobId to the $rememberItem session array.

Then when they want to see all of the jobs they asked to remember, I will  
display a page that calls the database using each Id to display the title  
and other info about each job. Then the user can print the page.

Is that the best way to do this?

Re: How can I keep data for users that are not logged in yet

Don Hobson wrote:

Quoted text here. Click to load it


Long question.
Short answer: sessions

A session can be started by adding session_start() at the beginning of each  
You store values in a session like in any other associative array, like  
$SESSION["visitorname"] = $MyReceivedName;

and retrieve this value from another page like this:
echo $SESSION["visitorname"];

You can store about any value and also complete arrays in a session.

Read more at, look up session.

Good luck,
Erwin Moller

Re: How can I keep data for users that are not logged in yet

Quoted text here. Click to load it

You need a way to identify users from each other.  Popular ways
for this include:

1.  Assign a semi-permanent login ID that the users enter.
2.  Use PHP sessions, which works for the duration of a session.
3.  Use a cookie to store a temporary identifier.  This method often
    ends up being a "poor man's PHP sessions", but with real sessions
    most of the work is already done.

WHY don't you want to put users in the database?  It's pretty much
required for (1) and (3), and I generally prefer to use a PHP
session handler that puts session data in a database.  It's much
easier to clean up than a directory that gets large (and therefore slow)
too quickly).

An IP address is *NOT* a good way to track users.  Imagine an office with
a NAT router and a single public IP.  You want all users in that office
to see each other's job selections?  This is a great way to get your
users fired.

Quoted text here. Click to load it

Use $_SESSION[].  How you organize that data depends a lot on your
application.  Putting an array in $_SESSION['selection_list'] is
one way of collecting a list of selected jobs.

Quoted text here. Click to load it

Different (simultaneous) users can share the same IP address.
The same user can have a different IP address on every hit (load-shared
proxies.  I believe this includes AOL).

Quoted text here. Click to load it

Site Timeline