Jump to content

Problem with code that's suppose to capture user information


andrew_ww

Recommended Posts

Hello,

I have attached some code which when its working is suppose to log various things when a user visits the site (IP, etc..) This script runs without giving an errors, but it does not update anything to database.  When I try to output what its captured the only thng it tells me that I'm localhost.

Does anything look out of place with it ?

-----------------------------
<?php
session_start();

$conn = mysql_connect("localhost", "your-db-login-name", "your-db-password") or die(mysql_error());
mysql_select_db("DATABASE-NAME", $conn) or die(mysql_error());

$sql0 = "select session from getinfo order by id DESC LIMIT 1";
$rslt = mysql_query($sql0) or print("The query: <B>" . $sql . "</B> gave the error <B>" . mysql_error() . "</B>");

if (mysql_num_rows == 1) {

    $session = mysql_result($rslt, 0, 'session');
    if (session_id() != $session) {
        $sql = "insert into getinfo values('', '$_SERVER[REMOTE_ADDR]','".gethostbyaddr($_SERVER[REMOTE_ADDR])."', '$_SERVER[HTTP_REFERER]', now(), '".session_id()."')";
        $query = mysql_query($sql) or print("The query: <B>" . $sql . "</B> gave the error <B>" . mysql_error() . "</B>");
    }
         
} else {

    $sql = "insert into getinfo values('', '$_SERVER[REMOTE_ADDR]','".gethostbyaddr($_SERVER[REMOTE_ADDR])."', '$_SERVER[HTTP_REFERER]', now(), '".session_id()."')";
    $query = mysql_query($sql);

}

$display_block .="
< p>You are visitor number $users.
< p>You are visiting from $host
< p>Your IP address is: $ip";

?>

----------------------------------------------------------

Thanks,

Andy.

[attachment deleted by admin]
Link to comment
Share on other sites

From your code snippit I would like to look at the bottom part

[code]
<?php
$display_block .="
< p>You are visitor number $users.
< p>You are visiting from $host
< p>Your IP address is: $ip";

?>
[/code]

I can not see in your script, where you are naming these vars
Link to comment
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.