Jump to content

Recommended Posts

Hi all,

I'm trying to autherise users, and then log activity, so I thought that this type of thing would work, but it's just not any ideas?


<?
require( "common.php" );  // where the vars for database login are stored

$auth = false; 

if (isset ($_SERVER['PHP_AUTH_USER'] ) && isset( $_SERVER['PHP_AUTH_PW']  )) {

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query="SELECT * FROM usernamepassword WHERE User = '".$_SERVER['PHP_AUTH_USER']."'AND Pass = '".$_SERVER['PHP_AUTH_PW']."'";
$result=mysql_query($query);
$num=mysql_numrows($result);

if ( $num != 0 ) {
$auth = true;
    }
}

if ( ! $auth ) {
    header( 'WWW-Authenticate: Basic realm="Private"' );
    header( 'HTTP/1.0 401 Unauthorized' );
    echo 'Authorization Required.';
    exit;

} else {

$query = "INSERT INTO log_user_activity ('UserID', 'URL', 'Time') VALUES ('1', '2',' 3')";


}
mysql_close();
?>

I was just trying to get the values 1, 2, and 3 into the database, and then work from there to get the userID the page and the time using system vars at a later date...

Is there somethig obvious that I've missed, or can anyone think of a better / more simple way..

Thanks in advance...


Dave
Link to comment
https://forums.phpfreaks.com/topic/18291-problem-logging-users/
Share on other sites

Personally, I prefer to store the query as a string, and then call it using the variable.  For example:

[code]<?php
                  $query"INSERT INTO logins (UserID, URL, Time) VALUES ('1', '2',' 3')";
                  mysql_query($query); //basically the same as what you done, except you have the sql  syntax stored as a variable, which is useful
[/code]?>

This way, like onlyican said, if anything goes wrong you can always 'echo $query' to ensure that all the variables are being passed correctly.  Other than that, onward and upward it is ;)
Link to comment
https://forums.phpfreaks.com/topic/18291-problem-logging-users/#findComment-78631
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.