writing to a table before calling a URL
writing to a table before calling a URL
(OP)
I want to monitor who calls a URL and when so I want the click on the link to write to a table before executing the link is this possible and how does a simpleton like me make it happen? Please keep it simple if possible.
RE: writing to a table before calling a URL
There is a pattern to use in PHP, where all urls are not directly accessing any file, but go through a routing.php to find a controller or through a single controller, if a site does not need a variety of controllers. And a controller.php might first check whether authentication/login has already been passed and is remembere in a current PHP $_SESSION.
A very general access permission check -eg also on html,jpg, pdf, and any other non PHP files - can only be done before PHP becomes active, and is rather a question about your webserver, though.
Bye, Olaf.
RE: writing to a table before calling a URL
Chris.
Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Never mind these jesus character, stars had to die for me to live.
RE: writing to a table before calling a URL
This can be easily done by calling a JS method off your anchor/link using simple onclick() method.
Say for instance:
CODE
Please note that I use JQuery and so, you will need to make sure you're loading the framework and that is beyond the scope of this post. That being said, same could be done using plain JS.
--
SouthBeach
http://www.fp2php.com
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
RE: writing to a table before calling a URL
Therefore the basic thing would be mod_rewrite (in case of Apache webserver)
2. JS binding to onclick events only is about literally clicking links. If you want to know user,uri about each http request this is again about the webserver. In general there is an access log in a logs folder (again rather Apache), and to have user information in it you have to specify a LogFormat with %u, see http://httpd.apache.org/docs/current/mod/mod_log_c..., but this will only be set after authetication and not after your own PHP login authentication but after http authentications as specified/restricted via .htaccess
So, do you see why I say this is rather a web server topic in the first place? All this stuff goes back to apache, first. To be able to tackle this with PHP some requirements have to be fulfilled in the first place, you have to plan an URL schema which makes every url, even those for non php files be routed by mod_rewrite to some php script processing the request, which is called routing. Otherwise the normal file extension pass by any PHP script and are only processed by guess what? The web server.
Bye, Olaf.
RE: writing to a table before calling a URL
SouthBeach, please note that links can be followed by other actions than clicking. In my FireFox 48.0 I can open the link on my test page without triggering the onclick event using :
- link context menu | Open Link in New Tab
- link context menu | Open Link in New Private Window
- middle click
- mouse gesture on the link ( any of the 6 link opener commands of FireGestures )
Regarding the original question, is kind of blurry. If we take it literally- "who" - if he means logged in user, maybe not the web server's access log is the best approach
- "a URL" - if he really means it at singular, maybe implementing routing is an overkill
sunbase, a more precise description of your goal would bring suggestions better fitting your need.Feherke.
feherke.ga
RE: writing to a table before calling a URL
That's why I said user ... "after http authentications", not after his own authentication/login, the webserver has no idea about php $_SESSION variables, for example.
You may associate ip address to logged in user, live or as aftermath. The web server access log has the big advantage it captures any access to anything. That's why tools for web site traffic statistics simply evaluate the logs. You may even have something preinstalled.
If you want to analyse web site traffic, another state of the art approach is outsourcing that, eg to google analytics.
Bye, Olaf.
RE: writing to a table before calling a URL
Yes, that was my first reaction too when initially read the question. ( Even wrote half answer very similar to yours, just delayed it then you posted in meantime. Doh, now I see you did it today too.
Feherke.
feherke.ga
RE: writing to a table before calling a URL
Course it will, ... A link, is a link, is a link, regardless of what happens to be in the position of anchor text, and covers the requirement stated in the first post:
Now IF "I want to monitor who calls a URL" actually means "I want to see the incoming referrals", that is already in the server access logs, and does not require anything additional.
Chris.
Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Never mind these jesus character, stars had to die for me to live.
RE: writing to a table before calling a URL
Bye, Olaf.
RE: writing to a table before calling a URL
No, because that would make it a javascript question and solution.
It's a really simple concept;
This is the basic PHP code I have used on sites for tracking affiliate links.
Also in attached file
CODE --> php
The code above goes in a document local called jump-2-uri.php (for example).
And the link needs to be one with a single parameter,
CODE --> HTML
Then when that link is clicked, the user agent requests the 'jump-uri' the code reads the parameter (amazon) matches it against the associative array keys and then redirects to the target URL (amazon.co.uk) in the array values.
To extend it is also easy, the assoc array moves into a database and instead of a 'name' you replace it with an ID that is produced when you add the entry, and hey presto! You have the basis of a short URL system.
As I said a couple of posts back tracking referrals is only a matter of checking access logs but if you want to do that with PHP it is also possible.
Chris.
Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Never mind these jesus character, stars had to die for me to live.
RE: writing to a table before calling a URL
Well, sunbase, you see your question raises many interpretations.
I can even come up with another one, assumed you want to know where employees surf the web, then you neither have control about the links themselves and could route them through some php, nor you detect the URLs visited on your sites webserver, as you don't host all the internet. The point of interest then is your endpoint, router.
There are many different topics around this question, so please rephrase what you want to count more specific. Traffic on your web site? Traffic to one certain link? Traffic to external sites off your site? Traffic to whatever sites from your office employees? There is no single point you can act on any of these URLs to count their usage.
Bye, Olaf.
RE: writing to a table before calling a URL
This: [emboldening and punctuation added]
[edit after pressing wrong button]
Suggest the following to me; When a visitor on my web site clicks a link, I want to know about it.
So that is the question I have answered. A philosophical discussion about what the TS actually meant serves no purpose as neither of us can actually know, so for the moment I shall remain agnostic as to why this thread exists until further clarification to that end is presented.
Chris.
Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Never mind these jesus character, stars had to die for me to live.
RE: writing to a table before calling a URL
I like your answer in the way it can even count links to external sites. You lack that count when only processing the access_log count. On the other side your way of counting link usage don't count the landing hits on the site. You can combine counting incoming and staying traffic with mod_rewrite routing every url for your website to a single url (script) counting the requests and provide links to external sites using your solution.
I still think it makes sense to ask sunbase for clarification and to provide the reasons and open his eyes for the different interpretations his question already had, even though he's explicitly stated wanting an answer for "a simpleton like me". It just shows one thing: The different interpretations have different solutions. And isn't that fine? Sunbase may also simply pick what he needs from the ideas already presented.
Bye, Olaf.
RE: writing to a table before calling a URL
Date 2016-09-09 09:00:00 User David Client Mr Jones Site pkprops.com
then open the URL www.pkprops.com
As it happens I have sorted it with an intermeidate page that runs the query to post then redirects to the URL - crude but it works.
As ever many thanks for all the input
RE: writing to a table before calling a URL
CODE --> jump.php
Then specify a call to jump.php?url=www.pkprops.com
Chris concept with an alias name has several advantages, though: Complex URLs with parameters in them are problematic as parameter value, because a url might contain ? and &, a parameter value can't. Also the html and browser status bar message already reveal the final URL and someone might circumvent the count, though that's maybe not much of a pain, as after leaving off once to the external site, a user might add this to favorites and from then on directly go there, you can't hinder that anyway.
Bye, Olaf.
RE: writing to a table before calling a URL
If you replace the "name" parameter in the anchor element href, with something like "affid" you will probably recognise the resultant URL as being an affiliate click-tracking one.
For example.
CODE --> html
so Amazon know what product to show the user and what affiliate account to credit any sale to.
The purpose of the script was to prevent the 'savvy' Internet user and possibly malicious ones removing the affiliate ID from the URL, thus bypassing 'your' commission, it also made content "stealing" and replacing the affiliate IDs somewhat more difficult for the 'lazy' affiliate types and the "crash and burn" 'marketers' who preferred to steal sites or 'pages', rather than develop their own.
This method is also somewhat more "Search friendly" and 'User friendly', simply because it keeps the link target URLs on the local domain rather than going 'off-site' to tinyurl.com, bit.ly or adf.ly
Chris.
Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Never mind these jesus character, stars had to die for me to live.