Jump to content

Statistics


Dawlish

Recommended Posts

New comer so do apologise if this is posted in the wrong place.

 

I'm working on a project that gathers the clients info (IP, Browser, Referral link and date+time of visit) which is then displayed in the browser in a html table,

I coded it so it wrote it to a txt file to check whether anything was happening (which it was) but i am now stuck on displaying it in a table.

 

Any help is appreciated!

Code below

 

 

<?php
 
$output = 'Log.txt'; /*This is the file where the data will be written to*/
 
@ $data = json_decode(file_get_contents("http://ipinfo.io/{$_SERVER['REMOTE_ADDR']}/json")); /*Gather the users IP and refer it over to the website which will return a json object which will be decoded and stored in $data*/
 
$filehandle = fopen($output, "a"); /*This opens the file declared in $output in append mode*/
if ($filehandle)
{
$string ='"'.$QUERY_STRING.'","'
.$_SERVER['REMOTE_ADDR'].'","' /*This writes the IP to the file*/
.$_SERVER['HTTP_USER_AGENT'].'","' /*This writes the users browser and OS to the file*/
.$_SERVER['HTTP_REFERER'].'","' /*This writes the the link that directed the user to this site to the file*/
.date("r").'"' /*This writes the date and time to the file*/
."\n"
;
$write = fputs($filehandle, $string);
fclose($filehandle);
}
?>
 
<html>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
border-spacing: 5px;
}
</style>
<h1>Statistics</h1>
<table width = "550px" height = "300px" border="1">
<tr bgcolour="#000000">
<th>IP address</th>
<th>Browser</th>
<th>Referrel URL</th>
<th>Date and Time</th>
</tr>
<tr>
<td>echo "$_SERVER['REMOTE_ADDR']"</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
 
</html>

post-206516-0-76619500-1513101388_thumb.png

Edited by gizmola
Code tags
Link to comment
Share on other sites

Hi,

 

I assume you mean something like:

?>

<table width="50%" align="center">

<tr><td>REMOTE_ADDR: <td/><td><?php echo $_SERVER['REMOTE_ADDR']; ?></td></tr>
<tr><td>HTTP_USER_AGENT: <td/><td><?php echo $_SERVER['HTTP_USER_AGENT']; ?></td></tr>
<tr><td>HTTP_REFERER: <td/><td><?php if(isset($_SERVER['HTTP_REFERER'])) {echo $_SERVER['HTTP_REFERER'];} ?></td></tr>
<tr><td>Date: <td/><td><?php echo date("r"); ?></td></tr>

</table>

<?php

Edited by BigB
Link to comment
Share on other sites

 

Hi,

 

I assume you mean something like:

?>

<table width="50%" align="center">

<tr><td>REMOTE_ADDR: <td/><td><?php echo $_SERVER['REMOTE_ADDR']; ?></td></tr>
<tr><td>HTTP_USER_AGENT: <td/><td><?php echo $_SERVER['HTTP_USER_AGENT']; ?></td></tr>
<tr><td>HTTP_REFERER: <td/><td><?php if(isset($_SERVER['HTTP_REFERER'])) {echo $_SERVER['HTTP_REFERER'];} ?></td></tr>
<tr><td>Date: <td/><td><?php echo date("r"); ?></td></tr>

</table>

<?php

Hi, 

You sir are an absolute genius i was stressing over this so much trying to get it to work!! 

Link to comment
Share on other sites

if you are doing a "whole php project" you might benefit from this style of coding:

$ra = $_SERVER['REMOTE_ADDR'];
$ua = $_SERVER['HTTP_USER_AGENT'];
if(isset($_SERVER['HTTP_REFERER']))
$hr = $_SERVER['HTTP_REFERER'];
else
$hr = '';
$dt = date('r');
$code=<<<heredocs
<table width="50%" align="center">
<tr><td>REMOTE_ADDR: <td/><td>$ra</td></tr>
<tr><td>HTTP_USER_AGENT: <td/><td>$ua</td></tr>
<tr><td>HTTP_REFERER: <td/><td>$hr</td></tr>
<tr><td>Date: <td/><td>$dt</td></tr>
</table>
heredocs;
echo $code;

 

Much easier to read and to maintain. Look up "heredocs" in the manual.

 

And if you really are doing a "project" you should look into getting rid of out-dated styles such as "align='center'" and use CSS.

  • Like 1
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.