Is there any way of registering clicks to a callto: link with the use of PHP? I've set up a site for a friend of mine and what I would like to do is to create a log of some sort to show who called who eg. if the current user clicks the callto: link I'd like to add a row to the database like "userX called numberY at hh:mm" but I've noticed you cant set variables in the callto: link as you would in ordinary links with just appending $var1=val etc...
I figured you could make use of the onclick()-method of the a-tag but I'd rather skip javascript at the moment and just use PHP. Anyone got any ideas for this? Is it possible to use the header()-function and "redirect" to the callto: link?
callto: is not http:, which means these links are not to be followed by a browser when you click them, but instead trigger activation of some program on the client computer associated with that protocol, right?
Which means no HTTP request is made, so you can't point them to a PHP script.
Which means the only way you're going to intercept these clicks is with JavaScript or by modifying the client software the browser launches itself.
I just did a proof of concept doing a redirect (in .NET), and it seems to work ok in Chrome, but it puts the following in FireFox (might be an artifact of .NET actually):
Object moved to here.
I guess you would do something like this: The user clicks on link to /docall.php?callto=blahblah. The contents of docall.php looks like this:
$callto = $_GET['callto'];
// log the call to $callto in the database
// send back the callto protocol response to the user.
header("location:callto:$callto");
Related
I am kind of new to PHP and I am just wondering if there is a way to REDIRECT a URL based on the type of client that the call has come from? Like if a user is clicking a link in a email client as opposed to a HTTP request.
Is there a difference? Can it be done?
So for example:
IF "http://somesite.com/somesubpage.php"
do THIS
ELSE if "EMAIL CLIENT"
do SOMETHING ELSE
Hope someone can answer this. It could be in PHP or in htaccess.
If a user clicks on a link in an e-mail, and the link opens in a web browser, this is still considered an HTTP request.
If you want to track clicks on links within an e-mail, one common solution is to add a query string to the link. For example, your homepage might be:
http://www.example.com/index.php
But from your e-mail, you can link to:
http://www.example.com/index.php?source=email
and then track the source variable from within the index.php script.
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.
I'm developing a website, but stuck at some point, where i needed to detect outgoing links on my website, and either forbid the links, or accept that, i don't know how facebook is doing this, but they can do it through facebook.com/l.php that if the link is marked spam, users will get notified about it.
I don't know if that's a php or htaccess, it worked in php using the DOMDOCUMENT, but it's not a real solution for this.
This is not something that you solve on the Apache or .htaccess level. Basically, whenever you're outputting a link, check if it's external, and if it is, change the destination to your redirector.
The redirector can then just check the URL passed, and if it's marked as malicious, it can show a message, and if it's not, then it can either automatically redirect or display some kind of notice that you're leaving the website.
I'm not 100% sure how Facebook is implementing it, but what I would recommend is to use JQuery (or another javascript library) to rewrite all external links to a validating PHP script (e.g. Facebook's l.php script), w/ the intended url getting passed as a GET parameter.
Using JQuery, it might look like:
$('a[href]').each(function(){
var safe_href = 'http://yourdomain.com/yourscript.php?url='+$(this).attr('href');
$(this).attr('href', safe_href);
});
You can can then do a database lookup in yourscript.php based on the variable $_GET['url'], and redirect to that url if it's safe or display a message if it isn't.
l.php is a script that reads links via $_GET['u']. With the url in the your hand you decide where you want the client to be redirected.
So as it looks, you want the users to teach your application what is spam and what not. For that you will need a button "report spam" beside the url.
If I have an app and it is run inside facebook. the first load I will get the
$_REQUEST['signed_request']
but if you click on any link inside my app and navigate within the app you will lose that $_REQUEST['signed_request'].
Is there any other way to know if my app is being run in a browser or inside facebook?
You can save value of signed_request in php session, something like this:
session_start();
if (isset($_REQUEST['signed_request'])){
$_SESSION['signed_request'] = $_REQUEST['signed_request'];
}
Later you can check if signed_request value is saved in session:
if (isset($_SESSION['signed_request'])){
//do something
}
You can continue to pass the signed_request around. Within your app, all your links should end with ?signed_request=<whatever> (or &signed_request=<whatever> if there is already a query string), and all your POST forms should include signed_request as a hidden input. Then you will always have access to signed_request.
If you really only need to know whether your app is being accessed through Facebook, the simplest way is to use a unique url in your app settings -- either a unique hostname like fb.yoursite.com, or a unique directory name like www.yoursite.com/fbapp/ . Then you configure your server so the unique hostname/directory points the same place as the regular hostname/directory. That way the same files can be reached either way, but your scripts can check the $_SERVER info to tell whether it's a Facebook request.
HOWEVER...unless you are strictly dealing with non-authorized access, you have to consider whether that will really solve anything. If you have to "detect" things like this, you must not be carrying any persistent state info, and your user will lose his "identity" as soon as he goes to page 2. So most likely, what you need to be considering is not a way to tell on each page whether the user is in Facebook, but rather a way to parse all the info you need on the first page and then make that available in all other pages. Many people use PHP sessions for this. Personally I think that's a bad idea, and would do something more like what Ben suggested in his answer (using GET and POST to pass the info you need).
Personally, a very simple yet effective solution I've used is some client side javascript (which can obviously be disabled etc) - this works nicely for a simple redirect and it won't work in every case.
// Redirect if the page is not an iframe
if (window.location == window.parent.location){
window.top.location = '{{ facebook_tab_url }}';
};
I am working on "Email this page" Popup page. I want to send url of base page as an email, but it should be a popup window.
I have used HTTP_REFERER, it is working fine on Firefox, but not working on Internet Explorer.
I am getting the url of current page but I want that url in new popup window page.
Is there any alternative than HTTP_REFERER.
On the page you wish to grab the URL of, you can use $_SERVER['REQUEST_URI'] to get the requested URI (except the scheme & hostname; in other words, you get the path and query string). Pass this to your other page either using a query string or sessions. The former is preferable, as the latter isn't RESTful. There may be times when it's OK to break REST's rule against server side state, but this probably isn't it.
There is no way unless you store it or send it yourself. This page has one example of how to do it, but only really if you set it beforehand. If the site is your own then you should be ok. If not then you will struggle.
That happens because the HTTP_REFERER is sent by the client browser, which means that it's value can be totally manipulated or can even be null. This means that this variable isn't very reliable. But if the site is yours, there are other solutions.
You can send the url or any other identification like an ID by QueryStrings. So you'll have the link URL like this the_send_page_name.php?ref=index.php
Be aware that this method only works if you're opening the Pop-up in a site that's yours.