simple question:
how to find the location (url) where a user came from before accessing my page?
and
how to find the location (url) where a user goes after exiting my webpage?
any ideas where i should start?
thanks
In PHP, you can use the $_SERVER['HTTP_REFERER'] to know where the user came from.
There is no mechanism to know where the user is going, unless they clicked a link on your site to leave your page. (If that is the kind of exit that you want to track, you'll need to rely on javascript and implement something like Google Analytics outbound link tracking: http://www.google.com/support/analytics/bin/answer.py?answer=55527)
To the first question:
Usually if someone comes to your page via a link or something like this a HTTP referer entry points to the refering page. See rfc2616
Second question:
If you have a link which links to an external page you may notice this by wrapping these links with some script. If someone types in a page by hand you will not be able to determine the location where the user went.
If the from page and destination pages are made by you, You can send the source page's url within GET or POST method and grab it in the destination and redirect user back to that url.
Related
Noob here! This is my first post - I apologise if it's been answered already.
I can't find anything in the search!
I have a number of sites in development and want to redirect them all to a single splash page for the company that owns them.
Is there a way to determine which url it was redirected from to allow different text and contact info to be called?
I can find lots of answers about using the current url - but not one that redirected to it.
Thanks for your help!
Like Kkinsey said in the comments - The first approach I would take is starting with $_SERVER['HTTP_REFERER']
Using Referer will work most of the time. Some browsers don't send it.
Instead, add a GET parameter to your redirection URL:
header("Location: http://main-company.net/splash?from=".$website_id);
exit;
Then retrieve it on the main website, if set it will be the variable $_GET['website_id'].
I'm trying to check whether the user has moved from a specific site.
But this site doesn't send $_SERVER['HTTP_REFERER'], so I can't use it.
Maybe some one knows, how to realise this:
1) User navigates to my site from example.com (no HTTP_REFERER)
2) When user loads my page, I need to check where this user is from.
Can this be done without the HTTP_REFERER header?
I answer IT.
I will use API on referring site.
Thanks!
I want to determine the website from which the request to the particular website has been called. For Example..I have a website www.ex.com. Now this website link has been there on three websites www.a.com, www.b.com, and www.c.com. Suppose one user has clicked the link from www.a.com to go to www.ex.com. Now I want to determine that the request has come from the www.a.com and then the page in www.ex.com will be displayed accordingly. Similarly if the user has clicked the www.ex.com link from www.b.com then the page will be displayed accordingly.
So how can I determine this request source, means from which website www.ex.com has been called? It is good if you will explain this using code in PHP.
Thanks
Look here for HTTP_HOST and HTTP_REFERER.
Since both global variables are populated from HTTP headers, look also here for Host and Referer.
That's how you use them:
$host = $_SERVER['HTTP_HOST'];
$referer = $_SERVER['HTTP_REFERER'];
The 1st is the original host name (like 'www.a.com') referring to your page. The 2nd is the full URL (like https://www.a.com/some/path/to/some.html).
Then, based on some conditional logic, you may return to your users appropriate HTML.
There are two different websites.
Say from a.com, you click on ex.com
So, for the link in a.com, add some parameter:
Click Here
Now, your from parameter will be
1) a.com
2) b.com
3) c.com
If none of the above, then its clicked from ex.com itself.
You can also add some encryption for this link to add security.
You can use this
$_SERVER['HTTP_REFERER']
for referral url
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 don't know is there is a PHP function like the ones that start with $_SERVER['']
That tell user which page he came from, on his current page.
ex. If I was browsing foo.com?id=abc then went to foo.com?id=efg, I need the current page to tell me that I came directly from foo.com?id=abc
I need this code badly, so any help is appreciated.
It is $_SERVER['HTTP_REFERER']. But it is filled only if browser did so. Otherwise you need to track user yourself (i.e. by storing last page in session)
The $_SERVER variables should not be relied upon to provide accurate answers. You should use PHP Sessions to track what page they come from, and simply update it everytime they go to a new page. Something along the lines of:
session_start();
if(!empty($_SESSION['visited_pages'])) {
$_SESSION['visited_pages']['prev'] = $_SESSION['visited_pages']['current'];
}else {
$_SESSION['visited_pages']['prev'] = 'No previous page';
}
$_SESSION['visited_pages']['current'] = $_SERVER['REQUEST_URI'];
Then to access the previous page, access the: $_SESSION['visited_pages']['prev']
The HTTP_REFERRER gives address of the page that requested the file. For example an image on a page is a separate request, and this request has a $_SERVER['HTTP_REFERRER'] set to the page.
I don't think browsers allow servers to access history. It can be done with JavaScript, though only a back button can be provided, the url cannot be accessed easily. Though it can be achieved using a simple css and javascript trick by accessing the computed color to a link.
Yes, and this is not only in PHP, this is a part of the HTTP protocol specification, Use:
$_SERVER['HTTP_REFERRER']