How to detect url from google ad link using php - php

How do i detect a user visiting from the google ad link. And if the user is from google url i need to perform some php function.
function google_ad(){
blahblah
}

One option is to try to check $_SERVER['HTTP_REFERER']. But some browsers may not send it.
Another option is just to add some GET param to your URL when you register it at Google (http://yourdomain.com?ga=1).

can you please used this code :
<?php
if($_SERVER["HTTP_REFERER"]=="url") {
// Some Code
}
?>
$_SERVER["HTTP_REFERER"]
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
Check On PHP Website
If it's for analysis purposes, you can use Goole Analytics and Google Webmaster Tools.
They both complement each other, and do pretty much want you want to accomplish with your script

Related

How to mimic Google Analytics utmz-cookie creation?

Now we are using standard google analytics script dc.js to create utm-cookies by http referrer and http url of the visitor. Now google stops creating utm-cookies since Universal Analytics.
Is there any way to mimic utm-cookie creation logic by referer and url using internal or external solution?
PS. Please, don't advise to get rid of utm-cookies. The main question is: "is it possible to create cookies by the same logic which google does?"
That is not realy easy. You can use the PHP function $_SERVER ['HTTP_REFERER'] but:
The address of the page (if any) which referred the user agent to the
current page. This is set by the user agent. Not all user agents will
set this, and some provide the ability to modify HTTP_REFERER as a
feature. In short, it cannot really be trusted.
As far as I know, the Universal Analytics HAS a way of tracking referrals using _ga cookies and it works very nice. If you work with PHP (hosted GA), then you will have problems but with JavaScript woks fine.
If you whant to follow AND _utm cookies with javascript, you need to create some "push" script what will collect that data but I think Universal Analytic have that option automaticly.
Read THIS blog please.

Prevent automatic Google shorten URL visit

When a user request a password reset, we send an email with a reset link shortened by Google URL Shortener.
Problem is, the link is being visited before / without the user clicking it. How can I prevent this?
// Google Shorten URL code.
$googer = new GoogleURLAPI($key);
$short_url = $googer->shorten($short_url);
return $short_url;`
You can't. Google will fetch the link to get information (such as the title) from it as part of the shortening service.
Just send a regular link like everyone else. You don't need it to be pasted into Twitter (where there is a message length limit) or posted on a billboard (where people have to type it).
I had the same problem and actually checking the HTTP referee doesn't help as in this case it doesn't display GoogleBot. I guess the machine checking the URL is really not the google bot used for crawling.
The only way i found to detect that it is google which is visiting the URL is by checking the IP address hostname and looking for google name in it.
Such as executing host 66.249.88.231 in a shell.
If you really need this solution, you could try to detect the Google Bot visiting your reset page.
It should send a specific user agent.

in my php page, I need the visitor facebook information.. possible?

I see some website detect my facebook name and offer a like button so I can the page I'm visiting. Can that be done in php? if not, how then?
Thanks
Facebook offers widgets for that matter, you can copy paste the code from the Facebook developer site: https://developers.facebook.com/docs/reference/plugins/like/
To get a visitor's name, tou could use Facebook javascript API https://developers.facebook.com/docs/reference/javascript/. You'll need to create an application and the user will need to authorize it before you're able to get any information. There are obvious security reasons why you can't get your visitor's name.

How to check user has liked(+1) google+ button on website or url?

How to get like status of google+ button on website or url? I am using PHP.
Unfortunately this isn't quite possible. Neither the REST API nor the PlusOne button itselfs provides a method to check whether a user has +1'd the page or not. Furthermore, if you're using PHP, the user would have to authenticate himself first (using OAuth), so that's probably not what you want, anyway.
What you can do, however, is using Javascript to catch actions of the current visitor. You can specify a callback parameter when creating the +1 button which will be called everytime when the user clicks on the +1 button (source).
While this approach doesn't provide you any information about who the user is (in terms of Google+ user), you could track his actions on your server using a cookie or something else. Or, if that's sufficient, just use the information for the duration of his stay.
if you are trying to get the statistics of your website's +1s, google's webmaster tools will provide the data.
YOu can get this from +1 metric menu in left panel in webmaster tools

How to use OpenID+OAuth in my website?

I want to log in my website by using google account, now i can use google account to log in(by OpenID), but i don't know how to get user account and information in google?
Just like below link(which is provided by google)
http://googlecodesamples.com/hybrid/
This link can log in by user's google account, and list all the documents in user's google doc, so i guess by using OAuth can let me get user's account(such as example#gmail.com) and get relative information, but i don't know how to do?
PS. I use php to write my website
I can't code the whole thing for you, but I'll try and give you a general outline of how it's done.
Sample Request URL:
https://www.google.com/accounts/o8/id
?openid.ns=http://specs.openid.net/auth/2.0
&openid.ns.pape=http://specs.openid.net/extensions/pape/1.0
&openid.ns.max_auth_age=300
&openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select
&openid.identity=http://specs.openid.net/auth/2.0/identifier_select
&openid.return_to=http://www.example.com/checkauth
&openid.realm=http://www.example.com/
&openid.assoc_handle=ABSmpf6DNMw
&openid.mode=checkid_setup
&openid.ui.ns=http://specs.openid.net/extensions/ui/1.0
&openid.ui.mode=popup
&openid.ui.icon=true
&openid.ns.ax=http://openid.net/srv/ax/1.0
&openid.ax.mode=fetch_request
&openid.ax.type.email=http://axschema.org/contact/email
&openid.ax.type.language=http://axschema.org/pref/language
&openid.ax.required=email,language
Then, you should receive this response URL as a redirect that you need to intercept:
http://www.example.com/checkauth
?openid.ns=http://specs.openid.net/auth/2.0
&openid.mode=id_res
&openid.op_endpoint=https://www.google.com/accounts/o8/ud
&openid.response_nonce=2008-09-18T04:14:41Zt6shNlcz-MBdaw
&openid.return_to=http://www.example.com:8080/checkauth
&openid.assoc_handle=ABSmpf6DNMw
&openid.signed=op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle
&openid.sig=s/gfiWSVLBQcmkjvsKvbIShczH2NOisjzBLZOsfizkI= &openid.identity=https://www.google.com/accounts/o8/id/id=ACyQatixLeLODscWvwqsCXWQ2sa3RRaBhaKTkcsvUElI6tNHIQ1_egX_wt1x3fAY983DpW4UQV_U
&openid.claimed_id=https://www.google.com/accounts/o8/id/id=ACyQatixLeLODscWvwqsCXWQ2sa3RRaBhaKTkcsvUElI6tNHIQ1_egX_wt1x3fAY983DpW4UQV_U
Once you get that URL, you all set! Hope this helps.
You may want to use already existing authentication solution, rather than reinvent wheel:-)
Since you are not specifying what server scripting language you are using, e.g. for PHP take a look at:
http://opauth.org/
It's pretty easy implementation and supports not only google account but many others.
It also pulls out some of account information you are interested in.
... or google for something like "openID authentication framework" or "oauth framework":-)

Categories