Jump to content

[SOLVED] One Time Update Only


jandrews3

Recommended Posts

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

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;
				}
?>



Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.