Dynadot โ€” .com Transfer

Optimizing my forum sessions (php)

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
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
NameMaxi - Your Domain Has Buyers
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back