0

First a little bit about me because it might help:

I am NOT a professional coder, I write HTML and CSS by hand with notepad++ because i like the lightweight and effective code + I have total control and clue of what is going on in my files/website.

I don't like WP. Its too much hassle and yes i know it's "easier" but since I know nothing about php, except that it's a server side language, it's not easier for me to get the look of the website that I want with it. (recently I found out I can INCLUDE a part(s).html in actual.html and compose actual.html - not up for that right now as it makes a new connection for each part.html (when i get to more complex web-developing, as my sites are static, etc...)) Tried multiple times, ended up deleting everything and writing my own code from scratch. I don't like to learn the (php) code from WP editing (extremely time-consuming and messy), I prefer learning it by using the code when i need it. That's how i remember and learn. That's how I learned C#.

I like one-file type of web pages as they are pretty much static. Any pics that i might use i DON'T create any links, I convert them in base64 and paste the code where i need it. So as minimalistic as possible with fewer requests as possible with least kb as possible - but resemble WP by look and behavior (responsivness).
I reserve one request for style.css and one for favicon.ico; #1 it's neater, #2 can't be base64-ed nor CSS loaded.

Anyway, a php contact form that I used in one of my sites was working perfectly, with just contact.php file on the server and a little bit of js in html. Therefore i ASSUME that fetching user data such as IP, time of access, screen resolution and OS would be easy similarly as the contact form was.

What I would like to know is next:

 fetch device.useragent + device.resolution + time + IP;
 write fetched to log.txt

Then i ftp the log.txt to my pc and investigate.

Thank you for reading and considering to help :)

Gokku San
  • 1
  • 2
  • You can get a part of your needs by a few lines of PHP code and some others by using a library ! It's already explained in one answer here :) –  Feb 24 '17 at 14:09

2 Answers2

1

The user agent, time, and IP address can be stored in variables as follows:

$userAgent = $_SERVER['HTTP_USER_AGENT'];
$time = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];

For resolution, you'd have to determine it with JavaScript and send it to the server with an AJAX request or as part of the request body. All of this can then be written to a log.txt file using file_put_contents('path/to/log.txt', $data);.

Note, that there are usually simpler ways of achieving this if using a framework (e.g. Symfony, Laravel, Zend), or there may even be a plugin for your CMS of choice.

Sheraz
  • 160
  • 8
  • 1
    wow.. Thank you for a blazingly fast and on-the-spot reply :) I'll make sure to add stackoverflow.com in my footer copyright signature as a helping hand of almost all websites i wrote ^_^ – Gokku San Feb 24 '17 at 14:29
0

Check this post, PHP's get_browser, and also this post is very helpful.
For the resolution, like Sheraz said, you need JS or any JS library that can read the device resolution. If you want to use jQuery, check this post.
To fetch user time of access, you can create a $_SESSION variable and use time.
For the ip, check this.
And for file handling, fopen, file_get_contents, file_put_contents and fclose will help you.

Community
  • 1
  • 1
Condorcho
  • 503
  • 4
  • 12