S
S
Skinner2015-06-24 23:52:02
PHP
Skinner, 2015-06-24 23:52:02

How to store the results of cookies in the database?

Good day!
I'm trying to write a cookie that would do the following:
1. First check the new user or not
2. If it's new, then add the user's data to the database (poppy address, browser, transition link ...)
3. If tagged, then just update information about it.
Can't figure out how to store data in a database?
here's what happened:
<?php
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
extract($HTTP_COOKIE_VARS);
extract($HTTP_SERVER_VARS);
//then I declare variables
$fileName="stat.txt";
$maxVisitors=10000;
$cookieName="visitor";
$cookieValue="1";
$timeLimit=0;
//pass from the moment of the last visit to the site, so that
//information about the visitor is recorded again. This
//value is equal to 1 day, i.e. the same visitor
//is recorded in the statistics once a day. If
//this variable is equal to zero, then
//all visits of the same visitor will be taken into account //
followed by variables responsible for displaying
//statistics
//Function for recording visitor data
function saveUserData() {
GLOBAL $fileName, $ HTTP_USER_AGENT, $REMOTE_ADDR, $REMOTE_HOST,
$HTTP_REFERER, $REQUES_URI;
$curTime=date("dmY @ H:i:s"); //current time and date
//prepare data for writing
if (empty($HTTP_USER_AGENT)) {$HTTP_USER_AGENT = "Unkwnown";}
if (empty($REMOTE_ADDR)) {$REMOTE_ADDR = "Not Resolved";}
if (empty($REMOTE_HOST)) {$REMOTE_HOST = "Unknown" ;}
if (empty($HTTP_REFERER)) {$HTTP_REFERER = "No Referer";}
if (empty($REQUEST_URI)) {$REQUEST_URI = "Unknown";}
$data_ = $HTTP_USER_AGENT."::".$REMOTE_ADDR ."::".$REMOTE_HOST."::
".$HTTP_REFERER."::".$REQUEST_URI."::".$curTime."\r\n";
//delimiter will be two ":"
//then write to the file
if (is_writeable($fileName) ) :
$fp = fopen($fileName, "a");
fputs($fp, $data_);
fclose($fp);
endif;
function definition_mac() {
if(PHP_OS == 'Linux'){ $macAddr = exec("grep ".$_SERVER['REMOTE_ADDR']." /proc/net/arp | awk '{print $4}'"); }
elseif(PHP_OS == 'WINNT'){
$ipAddress=$_SERVER['REMOTE_ADDR'];
$macAddr=false;
$arp=`arp -a $ipAddress`;
$lines=explode("\n", $arp);
foreach($lines as $line){
$cols=preg_split('/\s+/', trim($line));
if ($cols[0]==$ipAddress){ $macAddr=$cols[1]; }
}
};
return $macAddr;
};
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IceJOKER, 2015-06-25
@IceJOKER

What year did you write this code? O_O
Whoops, delete the file with this code and start again.
And the answers to questions - 2,3 you will find on the Internet, there is so much information on this subject that you can just ohrnt.
COMPLAINT-> THE ANSWER IS EASILY SEARCHED BY THE SEARCH ENGINE...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question