executing tracking script on external link out - php

I am curious on the best way to execute a database query and set a cookie when a user clicks an external link, without having that script passed to the browser history so when the user goes back from the external site they will land on the same page they clicked the link and not the page that executes the tracking script.
I noticed google tracks on an external click, not sure how but I see there is a mousedown event that possibly changes the href location of the link to their tracking script?
How can I achieve a similar function?

Here is a solution for tracking clicks I posted earlier today:
counter for number of clicks on links in php

Related

Changing browser history in php

i have a webpage, done with php (start.php&number=1)
On this webpage, there is a link to increase the number everytime i click on it.
This works perfectly fine. If I click it 99 times, the url is start.php&number=100
Now when i click the back button in my browser or swipe left on my phone, it just goes back to start.php&number=99. Although this is really reasonable, i just want to go back to the page before I visited start.php.
For example facebook if I was on facebook before I visited start.php
Is there a way to do this
You can't change the browser history. But if you don't want the browser to regard the new number as a different page then you need to
Use javascript to increment the number client side only.
Or use an ajax call to increment it at the server and display it at the client by updating a portion of the web page.

Active button in my email using php

am trying to put a button in the email created with php so that when the user gets that email, they can click the button to delete a record in the database directly without leaving the email client or email window they are in.
is it possible and how do i achieve that? Thanks.
The closest you can get I think is putting in a hyperlink to a web page which will automatically trigger the deletion when given the correct parameters. But it will still launch a web browser (and then a server-side script must run to do the deletion or whatever). And therefore you'll probably want to provide some feedback to the user on that page as well.
No, this is not possible. At best your email will contain a link that will spawn a new window or tab that will access a page to delete the record.

How to display message if user clicks on browser button?

My question is it possible to display a message if browser buttons have been pressed in order to be able to display a message stating if user should leave the page or stay on a page? Also can a message be displayed if user tries to change a url if they are on a certain page?
Thanks
Server side is needed for foolproofing this. On the server, when assessment is started, you should first have start screen URL. You must program it so that once assessment is started (after clicking start), it goes to the exam URL, and your assessment is always saved - when user goes back, using server side tricks have it so that instead of showing the start screen, it redirects back to the correct page (in a way that still maintains history), shows the exam with the data still in it, and pops up the warning not to click back button. Then, if user does it again, it does the same thing, again.
You have to have it so the exam is saved all the time. unload javascript event can be used to notify via alert() that they shouldn't be leaving the exam, and thats about all. onbeforeunload event can be used to try to give them the choice to stay, but shouldn't be depended on as it doesn't work on every browser.
Use onbeforeunload as suggested in a comment. There are various example, like this one: https://web.archive.org/web/20211028110528/http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm
If you want to call out the buttons that the user must click, you will need to do some browser detection, as most browsers have OK/Cancel buttons on the window that they display, but Chrome has "Leave this page" and "Stay on this page".

make webpage counters work in redirects

I'm writing a php program that redirects user to a page.(something like link shortener)
I want count pages visits without using mysql or etc. so I chose to work with a page counter service like histats but to make these services to work webpage has to be opened by user and a jsp or embeded flash has to be runned in user browser. but my program redirects user to another page that doesn't belongs to me and page on my domain wont be opened!
is there any way to make these counters to work?
You cannot normally force the user to call the counter URL. Especially when you redirect the client via http. You may save the hits in a plain file or any other database.
You should also know that the user maybe blocks the counter with an adblocker when you use a please wait for redirection message. Instat of redirect directly.

Tracking user specific exit links

I want to track exit link of a logged in user. I want to study their page navigation according to their demography. I have all the details needed in profile table.
I just need to know the exit link. I don't know how to do that. May b with PHP/Mysql/Javascript.
And the exit links can be from adsense.
Can u guys put me in right direction ??
FYI: Google analytics and other sites like that can't help coz I need stats of individual user according to his/her userid not of all them combined.
Add an onclick handler for all your links that you consider "exit links".
In this onclick handler, send an AJAX request to log the exit link. Depending on the network speed etc. the request might or might not be sent. If you always want it to be sent, prevent the default handler of the link and redirect to the link's target manually after the AJAX request has finished. That's not a good user experience though if the network connection is slow as the link will not react immediately.
Can the unload Event be Used to Reliably fire ajax Request? might also be interesting for you.

Categories