For my website, i'd like to track unique page views. to do this i figured i'd
use sessions in php and update a database each time. before, i tried using
session_var's to store the session, but i couldn't get that to work. so now,
i'm trying to use cookies to store the session_id. however, everytime a page is
refreshed, it will still update the db. i've printed the session_id, and it will remain
over page changes, but it will still update the db. =(
any suggestions?
here's my code so far::
<?php
if (session_id() != $idvanx_session) {
session_start();
$db = pg_connect('XXXXXXXXXXXXXXXXXXXXXXX');
$sql = "
UPDATE
hits
SET
count = count + 1
WHERE
page = 'main';
";
$result = pg_exec($db, $sql);
$id = session_id();
setcookie('idvanx_session', $id);
}
?>
:disgust: i wish there was a
use sessions in php and update a database each time. before, i tried using
session_var's to store the session, but i couldn't get that to work. so now,
i'm trying to use cookies to store the session_id. however, everytime a page is
refreshed, it will still update the db. i've printed the session_id, and it will remain
over page changes, but it will still update the db. =(
any suggestions?
here's my code so far::
<?php
if (session_id() != $idvanx_session) {
session_start();
$db = pg_connect('XXXXXXXXXXXXXXXXXXXXXXX');
$sql = "
UPDATE
hits
SET
count = count + 1
WHERE
page = 'main';
";
$result = pg_exec($db, $sql);
$id = session_id();
setcookie('idvanx_session', $id);
}
?>
:disgust: i wish there was a
Code:
tag so this came out indented the way it should be.