473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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?
Oct 11 '06 #1
2 2068
Don Hobson wrote:
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?
Hi,

Long question.
Short answer: sessions

A session can be started by adding session_start() at the beginning of each
script.
You store values in a session like in any other associative array, like
this:
$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 www.php.net, look up session.

Good luck,
Regards,
Erwin Moller
Oct 11 '06 #2
>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.
Oct 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: d.schulz81 | last post by:
Hi all, We have about 10 different domains that are linked very closely and we want to identify and keep track of every single user that surfs our websites by the use of sessions. The problem...
4
by: Alex | last post by:
Dear netters, We are looking to build a SQL Server database that will be hooked up to a Web server (WebLogic or a .NET). The database will house data for multiple customers, and the...
4
by: Guadala Harry | last post by:
Is there any way for one Session to remove and update objects in another Session? I seriously doubt it, but thought I'd ask. Here's why: I have some data that is unique per user (or per session -...
5
by: Vishal | last post by:
Hello, I already asked this question in the ASP.NET forums, but no help came. So I am hoping that somebody can help me out. This is really very URGENT me. For my e-commerce application, I...
2
by: dhnriverside | last post by:
Hi guys I'm trying to create an updated list of which of my AD users are logged onto each computer - there's about 29 computers and we use hotdesking! I'm using Windows Integrated...
6
by: laredotornado | last post by:
Hi, When a user logs into our site, we create a session variable to denote the session is active and another to denote who is logged in. Once the user closes the browser and re-opens it, the...
8
by: Mike P | last post by:
What would be the best way of counting the number of users who are currently logged on to a website? I am making the users login against a database of valid users. Would the best way be to add a...
7
by: Garry Freemyer | last post by:
I've researched this question on internet, and I've tried a number of things I found to no avail to solve this problem... I work for a company using Visual Studio 2003 to maintain a website for...
13
by: snowinfo | last post by:
Hi all, any way to count the number of users i have logged into my site? any help/code appreciated, craig
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.