Jump to content

PHP URL Redirect Help


Monj87

Recommended Posts

:wtf: I know i suck at php but i need help lol.

 

I just started working at this medical company in encinitas and one of their sites is really janky so in a few browsers like older IE and firefox you can't even navigate through the site.

 

I dont have time to spend on fixing it now so i wanted to use something like this.

 

do you know how to make a conditional like this but make it say If the user is in firefox 2 it will redirect them to a seperate location.

 

I already have conditional style sheets setup but the firefox 2 issues are beyond styling because it is a massive shopping cart and its not shoppable on firefox 2 so I will send them to my older site that works correctly on firefox 2 I need to start studying more php lol.

 

<?php

$referer = $_SERVER['HTTP_REFERER'];

$domain_name = "somedomain.com";

if(strpos($referer, $domain_name)!== FALSE) {

header("HTTP/1.1 301 Moved Permanently");

header("Location: http://www.yourdomain.com/newpage.php");

exit;

}

?>

 

Thank you!! :P

Link to comment
https://forums.phpfreaks.com/topic/244785-php-url-redirect-help/
Share on other sites

would you be able to tell me how to use 'HTTP_USER_AGENT' in this code to make somedomain.com/about-us.htm redirect to somedomain2.com/about-us.htm if the user is on firefox 2 browser?

 

<?php

$referer = $_SERVER['HTTP_REFERER'];

$domain_name = "somedomain.com";

if(strpos($referer, $domain_name)!== FALSE) {

  header("HTTP/1.1 301 Moved Permanently");

  header("Location: http://www.yourdomain.com/newpage.php");

  exit;

}

?>

http://php.net/manual/en/reserved.variables.server.php

 

Maybe you can use $_SESSION['HTTP_USER_AGENT'] like xyph said and then use str_replace or preg_replace to pull it apart.

 

You'll need to test that variable using different browsers so you can relate the output to different browsers as accurately as you can.

if this helps you

 

  <?php
		$HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
		function str_present($str,$substr)
		{
		$pos = strpos($str,$substr);			
		if($pos === false) {
		 return false;
		}
		else {
		 return true;
		}
		}
		if (str_present($HTTP_USER_AGENT, "Opera/9.27"))
		{
			header('location: url1');
		}else{
		    header('location: url2');
		}
		?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.