Dawlish Posted December 12, 2017 Share Posted December 12, 2017 (edited) 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> Edited December 13, 2017 by gizmola Code tags Quote Link to comment Share on other sites More sharing options...
BigB Posted December 12, 2017 Share Posted December 12, 2017 (edited) 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 December 12, 2017 by BigB Quote Link to comment Share on other sites More sharing options...
Dawlish Posted December 13, 2017 Author Share Posted December 13, 2017 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!! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted December 14, 2017 Share Posted December 14, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.