Hi all,
I have a PHP code that is to be used on specific pages within my site. When a user lands on the page from a specific domain OR a specific URL that has a tracking ID (ex: www.mysite.com OR www.mysite.com/?tid=1) the code is suposed to take them to another specific site or page. Bottom line, the code as is is not working now.
Also FYI, I am not a coder so take it easy on me. Just would like someone to tell me what to correct to make it work.
Also, I used Sharepoint to create the index.php file. I simply pasted the code into a new Sharepoint file, saved it with the .php extension and FTP’d it to the directory. When I tested it live with real URLs inserted into the code (not the ones in the attached sample, but real ones) the page is blank. It does not feedback an error, it just does nothing. Hope this additional info helps clarify the situation.
Thank you in advance.
Code:
[php]<?php
ini_set(‘display_errors’, 1);
class Redirector
{
/**
* Server data array
*
* @var array
*/
protected $_server;
/**
* Redirection maps
*
* @var array
*/
protected $_maps;
/**
* Class constructor
*
* @param array $server Server data array
* @param array $maps Redirection maps
* @return Redirector
*/
public function __construct(array $server, array $maps)
{
$this->_server = $server;
$this->_maps = $maps;
}
/**
* Get target for the specified host
*
* @param string $host Referrer host
* @return string|null
*/
public function getTarget($host)
{
if (array_key_exists($host, $this->_maps)) {
return $this->_maps[$host];
}
return null;
}
/**
* Return TRUE if referrer is available
*
* @return bool
*/
public function hasReferer()
{
return array_key_exists('HTTP_REFERER', $this->_server);
}
/**
* Get current referrer if available
*
* @return string
*/
public function getReferer()
{
if ($this->hasReferer()) {
return $this->_server['HTTP_REFERER'];
}
return null;
}
/**
* Perform the redirect
*
* @return bool
*/
public function run()
{
if (!$this->hasReferer()) {
return false;
}
$referer = $this->getReferer();
$host = parse_url($referer, PHP_URL_HOST);
$target = $this->getTarget($host);
header('Location: ' . $target);
}
}
// initialize the redirector and perform the actual redirect
$maps = array(
‘www.xyz.com’ => ‘http://www.123.com’,
‘www.lamesite.com’ => ‘http://www.123.com’,
‘www.coolsite.com’ => ‘http://www.123.com’,
‘www.bieber.com’ => ‘http://www.boohiss.com’,
);
$redirector = new Redirector($_SERVER, $maps);
$redirector->run();
[/php]