You are here: Re: How can I keep data for users that are not logged in yet « PHP Programming Language « IT news, forums, messages
Re: How can I keep data for users that are not logged in yet

Posted by Gordon Burditt on 10/12/06 00:32

>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.

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.

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

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.

>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?

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).

>$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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация