NameSilo

Optimizing my forum sessions (php)

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
Watch

nick-8318

Established Member
Impact
23
My current structure of planning is this:

table -sessions-
sid = sessionid
name = username (or default: guest)
lastclick = last recorded time of activity
ip = ip address of user

current rows:
1x1x1x1x, guest, 000000, 1.1.1.1

When a guest comes to a page:
(please note: code is shorthand, may contain common mistakes :/)

PHP:
$ip = getenv('remote_addr');
$userid = $_COOKIE['userid'];

if (empty($userid))
{
// user is guest
query("SELECT * FROM sessions WHERE ip='$ip' and name='guest' LIMIT 1");

$id = row('sid');
query("UPDATE sessions SET last_click='time()' WHERE sid=$sid LIMIT 1");
query("DELETE * FROM sessions WHERE lastclick<time()-10minutes");
} else
{
// Same thing but this involves a logged in user
}

Is there any better way to work this out? I do not like to run 3 query's on every page...when I could probably do it in less
I'm working on a forum and starting with 3 query's just for 1 member on each page is gonna slow things down from the start


thanks
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

A browser tab with a favicon next to the page title
Search members
You can now search for members by name, company, location and more. Open the search at the top of any page and choose Members. You will...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back