Page 1 of 1
traffic to a page first but another upon back button
Posted: Sun Oct 04, 2009 12:10 pm
by jasonst78
Hi everyone,
I am wondering if there is a way to implement something into this code that; (1) if the referer is set properly from google.com, it will always send the initial traffic to
http://mysiteA.com; (2) but when the back button is pressed it will send them to the other links besides
http://mysiteA.com.
Code: Select all
<?php
$ref = $_SERVER["HTTP_REFERER"];
if (strpos($ref,'google.com')!==FALSE) {
$urls = array
("http://mysiteA.com",
"http://mysiteB.com",
"http://mysiteC.com",
"http://mysiteD.com",
"http://mysiteE.com");
$url = $urls[array_rand($urls)];
header("Location: $url");
}
?>
Re: traffic to a page first but another upon back button
Posted: Sun Oct 04, 2009 3:11 pm
by Griven
Just so I understand, let me recap...
If a user visits your website from Google, and presses the back button to leave your website, you don't want them to go back to Google.com? If I'm right, then this sounds like a surefire way to p!ss off your visitors. I know I hate it when sites do that--I tend to never go back.
However, if you REALLY want to do that...
Make the landing page of your site an instant redirect to another page. That way, when they click the back button, they'll just be redirected again.
Re: traffic to a page first but another upon back button
Posted: Sun Oct 04, 2009 4:00 pm
by jackpf
I think browsers cache the redirects...so I'm not sure if that'd work. But yeah, this sounds like a rather annoying thing to do tbh.
Re: traffic to a page first but another upon back button
Posted: Sun Oct 04, 2009 4:12 pm
by Mirge
jackpf wrote:But yeah, this sounds like a rather annoying thing to do tbh.
+1... I wouldn't be back.
Re: traffic to a page first but another upon back button
Posted: Sun Oct 04, 2009 5:48 pm
by jasonst78
Well, actually the example I posted is just that, an example. The visitors will not necessarily be coming from Google. The reason I would like the visitors to be directed to another page upon pushing the back button is because I am receiving the initial traffic via a redirect. When the visitor makes an attempt to push the back button it simply refreshes the main page over and over and I agree with everyone this can be very annoying. Therefore, instead of the visitor continuing to see the same page when hitting the back button, I was hoping that I could redirect them to various other pages that I have listed in the array, with priority given to a chosen link. After the prioritized link is viewed once I was hoping to place a cookie that would prevent it from being viewed again.
@ jackpf - to prevent a cache from the redirect I have placed into the code:
Code: Select all
header("cache-control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
Re: traffic to a page first but another upon back button
Posted: Sun Oct 04, 2009 10:10 pm
by Griven
I'm going to go out on a limb here and say that you can't do this. The reason being is that PHP is server-side code and only executes when a web client requests a page containing that code. By pressing the back button, the client is actually accessing a completely different page, the address of which is cached inside the browser. To do what you are describing, you would need to essentially hijack the user's browser by inserting what could only be described as malicious code (even if your intentions aren't malicious).
I believe the code that you displayed there controls whether or not the content of the page is cached--not the address.
Re: traffic to a page first but another upon back button
Posted: Mon Oct 05, 2009 5:35 am
by jackpf
Sorry for being stupid, but I still don't understand the point of doing this
And yeah, I agree...it doesn't sound possible, since when the user hits the back button, the page is loaded from cache. Although, with your no-cache headers, I'm not sure what would happen...I'm not sure what kind of referrer the browser would send. You could give it a go though...by checking $_SERVER['HTTP_REFERER'].