Trying to capture IP addresses in wordpress / php script - php

I would like to keep track of IP addresses visiting my site, as it helps determine what content I should host.
I a really not a programmer, so i was looking for a pre-built solution.
I found this script:
<?php
$LogFileLocation = "/public_html/cms/iplog.txt";
$fh = fopen($_SERVER['DOCUMENT_ROOT'].$LogFileLocation,'at');
fwrite($fh,date('dMy H:i:s')."\t".$_SERVER['REMOTE_ADDR']."\t".$_SERVER['REQUEST_URI']."\n");
fclose($fh);
?>
however when i created iplog.txt and browse to it, nothing happens.

If you need only statistic of visiting of your site why you don't use Google Analitics (http://www.google.com/analytics/)? It gives full information on how to track visits onto the site. Your method gives you only text file with date, user's ip and page which user visited; but if you aren't a programmer, you will not sort this information and operated this data.
If you still decide to use your method of store information and don't want to use Google Analitics, then save data about user and visited pages in the database in special created table (id, date, ip, uri). This method will permit show date-statistic, statistic for ip and single page.

You can capture IP of the visitor with the following code.
$ip=$_SERVER['REMOTE_ADDR'];
Now you can store it in your database. For that you have to create a column in your database table that stores the ip address. Along with IP address, you can store many other information in the database for keeping track of users like time stamp, duration, page visits etc. There are many tools available like Google Analytic and others which provide you such services free of cost but they don't store the record in your website's database. So choose accordingly.

Related

Presenting visitors with regional content (province/state/county), amazon AWS

I am looking for a automatic way to link a website visitors's location to regionally limited content (not based on distance from lat/lon). The content is generated by a static site generator for each countries' province and will be delivered to the user from Amazon AWS. (Cloudfront I guess, we haven't yet decided precisely) provinces will each have their own static directory and for instance be accessed through their own url (//province.website.country)
So for instance a visitor from Beieren, Germany, must see only content that is published to Beieren, when the enter "website.de", get redirected to the beieren sub-url.
A possible solution is to present the user with a map in which they click on their region. However, we prefer to do this automatically when the information is present in the request headers/ip info.
I wonder what methods are out there except from comparing huge lists of ip ranges to ip/location databases and then getting the province from that location. For instance we are willing to use perverted methods like requesting google user data. But perhaps Amazon AWS provides a way to do this. We haven't been able to find it.
Most of all, we are looking for the fastest and most reliable way.
AWS does not provide any method of doing this.
Further, without asking the user where they are you generally have to rely on their IP address which is only really accurate in giving you the location of their ISP. I've seen IP address based geolocation be wildly inaccurate, so I wouldn't rely on it for anything important. If a user is on a mobile device you might be able to request GPS coordinates, but the user could always deny that request.

Discerning demographics of website visitors from user agent strings in table?

I have a db table that captures visitor info, including a user agent string. I'm trying to determine the demographics of browsers in order to prioritize web testing on higher incidence browsers/versions.
My question: user agents appear very similar to me; is there any way I can write a query to differentiate the strings into their representative browsers/versions?
Thanks in advance.
Note: my company does not have google analytics configured to track this info, and we need to measure data on file rather than waiting for new visitors.

Couting IP unique visitors and sending it to mysql database

I'd like to know how can i get information about uniques IP's to my site specify link and store that information in mysql database to particular user.
I need that script count not only http://example.com.com but also ex.: http://example.com/somesub/this/link.
Because i want to develop project in which users get traffic to my system and they get paid.
(Pay to Promote system).
How can i develop this? Any ideas about php code?
First of all use $_SERVER['REMOTE_ADDR'] to find the request IP Address or see How to get client IP address PHP.
then at the start of each page of your site you should get this value (which acts like a primary key) and do query to the database to increase the specific counter.
P.S: you will find problems in case the client is using proxy to get to your site, see the link above for more information.

Facebook App users on Google map

I need to create a Google map that would display all my app users. The problem is, that that Facebook doesn't seem to provide enough information to do that, country at most. I'd like to display user position on map at least to the proximity of the city.
The only option I see, is to track user's location using their IP. What are the other options?
If the user has provided it, you can get their current location (city, state, country) by prompting for the 'user_location' and/or 'friends_location' permissions.
You might also want to check out the 'user_checkins' and/or 'friends_checkins' permissions for more timely and accurate locations.
http://developers.facebook.com/docs/reference/api/user/
Or as a fallback, like you say, you can usually get an approximate location by their IP. But that's not always very accurate.

Save users activity

I am a web developer and I want to design a commercial website to sell a customer's product. Sell and buy activities are important and I need to maintain user activity information to keep the site secure.
I want to write a dynamic website. I want to control all user activity and then decide whether to save user activity information in a database. Some of site's visitors are registered users and some are anonymous. I want to save online information such as ip address, username, page name, and date/time for my registered users.
I want to know:
How do I save a user's IP address?
What more do I need to save?
Saving each HTTP request details into database will work for low traffic web sites, but you will have performance issues in case of popular website, since writing to database in relatively slow operation.
Why not to use server HTTP logs instead?
All HTTP web servers create plain text log files which record remote user IP address, URL requested, etc. You can create activity report by writing your own script or using log file report tools. AWStats ( http://awstats.sourceforge.net/ ) is one of the most popular open-source tools for this.
On client side you can use Google Analytics to track user activity. It also provides means to track custom events:
_gaq.push(['_trackEvent', 'login', 'user_login', "custom data"]);
More info at: http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html
This option only tracks users with JavaScript enabled, so it won't show bots, crawlers or users having analytics blocking addons installed.
I'm not sure I understand all of your question...but to address at least one aspect of it, if the user is behind a proxy, then you have no way of determining what their real IP is. That's the whole point. The proxy is the one making the request and then forwarding it. Without asking the proxy yourself, you cannot determine that. With regards to what else you need to save, it depends entirely on what you want to do and you haven't done a good job of explaining why you are saving this data. If you can clarify that, perhaps we can help you a bit more in determining what data you should be saving.
Edit To address your clarification, if you wanted to be crazy, you could log everything that a person does. Every link they click, every product they view, etc. I don't necessarily advocate that as I find it a bit creepy, but there are definitely sites that do it. At the bare minimum, I would suggest logging what products people look at and then what products they buy. I would also log that information on a per-session basis. Basically, what products do people look at and then end up buying on the same trip to your store. I wouldn't worry too much about the "real" IP address. Most people won't be behind a proxy and those that are, you can't do anything about anyway.
How do I save a user's IP address?
$_SERVER['REMOTE_ADDR']
What more do I need to save?
That's quite strange question. It's your application, not someone's else. How can we guess what information you need?
However, at least one issue I can point out: a page name is not sufficient to log "all user activity". Query string and POST data usually contains important details on that activity.

Categories