▼  Site Navigation Main Articles News Search  ▼  Anime + Manga Anime Reviews Anime Characters Gallery Screenshots Manga Reviews  ▼  Misc Links to Webcomics Bible Quotes About Older Musings
site version 7.3
PHP/Javascript –– store user's stats in a file
written by: admin


Date Written: 10/21/08 Last Updated: 8/20/10

<?
$ipaddress = $_SERVER['REMOTE_ADDR'];
if(isset($HTTP_COOKIE_VARS["user_resolution"]))
$screen_res = $HTTP_COOKIE_VARS["user_resolution"];
else
{
?>
<script language="javascript">
<!--
writeCookie();
function writeCookie()
{
var today = new Date();
var the_date = new Date("December 30, 2022");
var the_cookie_date = the_date.toGMTString();
var the_cookie = "users_resolution="+ screen.width +"x"+ screen.height;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie
location = '/';
}
</script>
<?php
}
?>
<BODY>
<?php
$today = date("Y-m-d");
$fh = fopen("test_text.txt","a");
fwrite($fh,"$ipaddress $screen_res $today \n");
fclose($fh);
echo "Your Screen resolution is set at ". $screen_res;
echo "<br>Your IP address is $ipaddress";
echo "<br>Today's date is $today";
?>
</BODY>
</HTML>

This will detect the ipaddress, screen resolution, and create a file named test_text.txt where the stats are then stored.  If the file already exists then it will just update the file.

Here is a tiny sorting script I created to view the results.  $dates are the contents of the .txt file.
$dates=array("2008-10-21","2008-10-22","2008-10-23");
$text=str_replace($dates,"",$text);
$text=preg_replace('/\r\n.*?\s/','<br>',$text);
$text=explode("<br>",$text);
asort($text);
$text = implode("<br>",$text);
echo $text;


TAGS: javascript, php
copyright 2005–2024