Our website is currently using Google Universal Analytics to track goal conversions from our own private domain and a 3rd party payment processor. Currently our goal flow is:
/cart -> /checkout -> /receipt
On the /cart page which resides on our private domain, the user clicks "checkout". When they do, it goes to /precheckout which is a preprocessing script which finishes with header("Location: external.com/checkout"); exit;
Our suspicions lead us to believe that it's this intermediary page that is breaking our funnel. From what I understand, when header("Location: "); is used and no data is sent to the browser, that it should simply follow the redirect. What is happening?
I'm willing to bet that the server changing the location is causing the browser to not send the "Referer" header.
Try header('Referer: /cart'); in the /checkout.
Since the user is not clicking on anything in between precheckout and checkout, you need to manually set it. If the user isn't always going to be clicking that link to get to the checkout page (i.e. bookmarking it), it may be better to set a session variable to determine if they just came from the cart and if they did use the header code above.
The 301 redirect is the preferred way to redirect URLs, since it informs search engines that the URL has moved for good, and search engines should put the new URL page in the search results instead of the old URL page and transfer the new URL page, the page rank of the old URL page.
The 301 redirect can be done across domains or on the same domain.
Google ""analytics"" recommends to use 301 redirect.
<?php
// PHP permanent URL redirection
header("Location: http://www.example.com/new-page.php", true, 301);
exit();
?>
https://www.rapidtables.com/web/dev/url-redirect.html
Related
Using the PayPal API, when the user cancels the process or is redirected back to the shopping cart page in order to review the order, the page URL includes the GET paramenter "token". I don't want the user to see that token, so I redirect the page to itself without the query string, using a 301 redirect. Hovewer, the URL including the token is saved in the browser history (at least in Firefox and Chrome) and shows up as autocomplete option when typing in the address bar.
The PayPal express checkout API doesn't have a parameter to make the return requests POST instead of GET (as opposed to the form-based method with hidden fields). Is there any way to do a redirect that won't have the original URL saved in the browser history?
I also tried 302 and Refresh: 0; url=... - but that still saves the URL...
I don't think this can be done because the browser is seeing it as a unique URL and recording it to be helpful to the user. It's important for the browser to know the history, but I understand why you don't need to show this to the user.
If you weren't using the PayPal API, I'd suggest not using querytring values in the URL, but that's probably unavoidable in this case.
Sorry to say, but I think you're stuck with it. I never found a way around this in any PHP or Classic ASP applications.
How do I create a php which redirects with use of the URL. I.e. - Redirect-To.com/Change.php?=Google.com Then goes to google etc
I'm wanting to create a php page where a user goes to
Redirect-To.com/Change.php?=Google.com
or
Redirect-To.com/Change.php?=Youtube.com
or
Redirect-To.com/Change.php?=Yahoo.com
Then the visited page redirects to Google or whatever page is after ?=
This is basically what URL shorteners do, except they lookup the destination from a database and probably store some tracking information.
Check out the header function that lets you set HTTP headers. You want to set a 302 redirect, which means moved temporarily, and a Location header to set the new location.
http://php.net/manual/en/function.header.php
header('HTTP/1.1 302 Moved Temporarily');
header('Location: ' . $newLocation');
301 is another common redirect code, but it means "Moved Permanently" and a lot of browsers will cache that status and not hit your website if the person clicks your link again.
The HTTP spec says you should give the full URL with the redirect, though most browsers will work without it.
You may also want to white list destinations; a user might follow a link to your site and be redirected to a site owned by a a malicious third party. Thinking they were in the confines of your site, they may enter information or perform actions allowing the third party to gain access to their data.
In the URL, values without keys will be ignored, so you should write:
...change.php/?redirect=http://www.google.com
Then you can access the "redirect to" address with $_GET['redirect'].
To redirect to a given address, you can use to Location header (make sure nothing is sent to the output before calling the function):
header('Location: ' . $_GET['redirect']);
You have to start the redirecting URL with "http(s)://" like I wrote above.
If you want to stop the script (as it does not stop immediately after the redirect function), you have to call the die() or the exit() function.
(If a shorter URL is better for you, the URL can be just ...change.php/?http://www.google.com, then you can access the address with $_SERVER['QUERY_STRING'].)
I'm trying to redirect users to another page, however, I need the Referer header to show that there was a redirection. In other words, if the user starts on SiteA, then goes to SiteB, which redirects to SiteC, I need the Referer header to show that the user came from SiteB when they arrive at SiteC.
Most browsers don't change the Referer header when encountering a 3xx (301, 307, etc.) redirect code so I can't use that. So I'm wondering what the best way is to accomplish what I need? I have HTML, PHP, and if necessary JavaScript at my disposal.
Thanks,
Harry
P.S. I've done enough HTML, PHP, and JavaScript coding to get by, just not enough to know the answer to this question.
Correct me if I'm wrong, but the 3xx status codes is to tell the browser that the page has move, and that they are to request the page again at the new url. So to a browser, the current page has not changed, and thus the referrer will remain he same.
Use a javascript like location=url during page load to redirect the page instead.
I am trying to track a redirect page with google analytics:
I have a page called redirect.php; when I visit an url like redirect.php?c=12345678 , a php function does a query on a sql lookup table to decode the code 12345678 with a previously inserted url, then does a 301 redirect.
(I'm doing a 301 redirect to avoid duplicate content.)
I wish to track every single visit to redirect.php with analytics, but I can't.
For example:
redirect.php?c=87654321 redirects to story.php.
Obviously in Analytics I can't find the redirect.php page. the story.php referer is organic/google so I can't rely on the referer.
Is it possible to track every redirect in some ways?
GA works in the browser. Whenever the user visits a page with the GA script - a request from the user to google is sent notifying about the visit.
Since you are making a 301 header redirect - no GA script is loaded and therefore google doesn't know the user has been on that page.
Options you have
Switch the redirect from 301 header to a page with meta redirect and the GA code
Switch to another analytics system such as Piwik and add data to it manually on the redirect page
Implement your own counter inside the redirect script, separated from GA
Of course you could merge the options and have, say a page with meta redirect and the GA code, which redirects to redirect.php script, which in turn redirects with a 301 header, but this is not the best solution.
You need to add your Analytics code BEFORE the redirect.
I'm doing a 301 redirect on site A to site B - when the user arrives at site B it needs to find the page the user came from. This doesn't seem to be working though:
$_SERVER['HTTP_REFERER']
whereas if I do a link to the page
go
I get the referrer through. Is there a reason it doesn't come through after the redirect? If so can anyone offer any advice on how to do this. I want to avoid at all costs having a query string on the redirect.
Is there maybe another header I need to send with the page that redirects?
Thanks for any advice!
The thing is, the HTTP_REFERER is site A. That's just how a 301 works.
That said, the easy way to do this is to take the url of the referrer to site A onto the end of site B's URL as a variable. Then, at site B, any time you have a referral from site A, you can have it.
<?php
header("Location: http://site-b.com/?ref="
.urlencode($_SERVER['HTTP_REFERER']),TRUE,301);
?>
Then of course at site B, access urldecode($_GET['ref']) for your referrer.
However... if you're looking to avoid _GET variables, you have a few options.
A) Collect the _GET request, then re-munge the URL -- IE have site B redirect to a "clean" version of itself.
B) Have your redirecting page make a curl or stream_get_contents over to a "collection" page prior to issuing a header(), where you collect and store the any session information (like the refererer) and have it prepared to be processesed when they redirect.
You could try adding a CGI query string to the end of your URL when doing the redirect -- eg
http://www.site-b.com?redirectfrom=www.site-a.com
site-b.com would ignore the URL parameter, but it would be recorded in the logs and would be accessible from within PHP.
You can do it with javascript. Use the following script, but it between <head> and </head>
<script type="text/javascript">
location.href='http://www.site-b.com';
</script>
This will of course not make a proper HTTP 301 redir, but I just tested it, and it will send the referer (the referer being site-a).