jandrews3 Posted July 25, 2008 Share Posted July 25, 2008 I am using http authentication to restrict access to my website and am then storing the login in a database (MySQL). People are queued to login at the Members Area page, and then that login time is stored in the database as their 'last login time'. Of course the login script is at the beginning of every protected page to make sure no one can bypass it. BUT, here's the question, how do I prevent the update script from updating a new 'last login time' each time a person navigates back to the Members Area page from other pages within the site. Here is my code: <?php $link = mysql_connect("ositowebsolutions.com","••••••","••••••") or die("Could not connect: ".mysql_error()); mysql_select_db("••••••")or die("Could not select database: ".mysql_error()); $query = "SELECT * FROM ithf_members WHERE uname = '{$_SERVER['PHP_AUTH_USER']}' and pword = '{$_SERVER['PHP_AUTH_PW']}'"; $result = mysql_query($query) or die("Could not perform query: ".mysql_error()); $row = mysql_fetch_array($result); $uname = $row['uname']; $pword = $row['pword']; $id = $row['id']; if (!isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) || !($_SERVER['PHP_AUTH_USER'] == $uname && $_SERVER['PHP_AUTH_PW'] == $pword)) { header('WWW-Authenticate: Basic realm="Authorization Required!"'); header('HTTP/1.0 401 Unauthorized'); echo 'Authorization Required!'; exit; } else { ?> <html> <head> <title>ITHF International Travel & Hosting Fellowship</title> </head> <body background="resources/back5.jpg" bgcolor="2c3271"> <? $sum = $row['sum']+1; $last_log = date("d F, Y; G:i:s"); $query1 = "UPDATE ithf_members SET last_log = '$last_log', sum = '$sum' WHERE id = '$id'"; mysql_query($query1) or die("Could not perform update: ".mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/116586-solved-one-time-update-only/ Share on other sites More sharing options...
jonsjava Posted July 25, 2008 Share Posted July 25, 2008 Something like this (using sessions): <?php session_start(); $link = mysql_connect("ositowebsolutions.com","••••••","••••••") or die("Could not connect: ".mysql_error()); mysql_select_db("••••••")or die("Could not select database: ".mysql_error()); $query = "SELECT * FROM ithf_members WHERE uname = '{$_SERVER['PHP_AUTH_USER']}' and pword = '{$_SERVER['PHP_AUTH_PW']}'"; $result = mysql_query($query) or die("Could not perform query: ".mysql_error()); $row = mysql_fetch_array($result); $uname = $row['uname']; $pword = $row['pword']; $id = $row['id']; if (!isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) || !($_SERVER['PHP_AUTH_USER'] == $uname && $_SERVER['PHP_AUTH_PW'] == $pword)) { header('WWW-Authenticate: Basic realm="Authorization Required!"'); header('HTTP/1.0 401 Unauthorized'); echo 'Authorization Required!'; exit; } else { ?> <html> <head> <title>ITHF International Travel & Hosting Fellowship</title> </head> <body background="resources/back5.jpg" bgcolor="2c3271"> <? $sum = $row['sum']+1; $last_log = date("d F, Y; G:i:s"); if ($_SESSION['is_valid'] != true){ $query1 = "UPDATE ithf_members SET last_log = '$last_log', sum = '$sum' WHERE id = '$id'"; mysql_query($query1) or die("Could not perform update: ".mysql_error()); $_SESSION['is_valid'] = true; } ?> Link to comment https://forums.phpfreaks.com/topic/116586-solved-one-time-update-only/#findComment-599538 Share on other sites More sharing options...
jandrews3 Posted July 25, 2008 Author Share Posted July 25, 2008 Thanks. I've never worked with session, but the way you've written it looks pretty easy and similar to what I've done. I'll give it a try. Link to comment https://forums.phpfreaks.com/topic/116586-solved-one-time-update-only/#findComment-599616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.