0

There are 3 urls

I want a place a www.url2.com in in a page of www.url1.com and redirect it to www.url3.com (the script will be in www.url2.com) or when someone clicks on a link in www.url1.com - it goes to www.url2.com and a php script works and redirects to www.url3.com

The site www.url3.com should not be able to track www.url1.com

www.url3.com should only know about www.url2.com here is the php script. Please help me find a way.

Now I place a goo.gl (links to www.url2.com) link in www.url1.com and takes the user to www.url2.com and there the script takes user to www.url3.com But www.url3.com still shows the source url as www.url1.com !!! It can track the first url !! how ?

<?php


// change if you wish
$db = 'urls.sw';

// language/style/output variables
$l_nourl        = '<strong>No URL supplied</strong>';
$l_yoururl      = '<strong>Your short url:</strong>';
$l_invalidurl   = '<strong>Invalid URL supplied.</strong>';
$l_createurl    = 'Snip!';



if(!is_writable($db) || !is_readable($db))
{
    die('Cannot write or read from file. Pleae CHMOD the url file to 777');
}

$action = trim($_GET['id']);
$action = (empty($action) || $action == '') ? 'create' : 'redirect';

$valid = "^(https?|ftp)\:\/\/([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?[a-z0-9+\$_-]+(\.[a-z0-9+\$_-]+)*(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@/&%=+\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?\$";

if($action == 'create')
{
    if(isset($_POST['create']))
    {
        $url = trim($_POST['url']);
        if($url == '')
        {
            echo $l_nourl;
        }
        else
        {
            if(eregi($valid, $url))
            {
                $fp = fopen($db, 'a');
                fwrite($fp, "{$url}\r\n");
                fclose($fp);
                $id = count(file($db));
                $dir = dirname($_SERVER['PHP_SELF']);
                $snippedurl = "http://{$_SERVER['HTTP_HOST']}{$dir}/$id";
                echo "$l_yoururl <a href='$snippedurl'>$snippedurl</a>";
            }
            else
            {
                echo $l_invalidurl;
            }
        }
    }
}

if($action == 'redirect')
{
    $urls = file($db);
    $id   = trim($_GET['id']);
    $id   = $id - 1;
    if(isset($urls[$id]))
    {
        header("Location: {$urls[$id]}");
        exit;
    }
}
?>
Shijil T
  • 49
  • 1
  • 9
  • And what's the current issue? – Chay22 Apr 09 '16 at 04:40
  • @Chay22 – Now I place a goo.gl (links to www.url2.com) link in www.url1.com and takes the user to www.url2.com and there the script takes user to www.url3.com But www.url3.com still shows the source url as www.url1.com !!! It can track the first url !! how ? – Shijil T Apr 09 '16 at 04:44
  • The server can't set HTTP referrer to the client. I think the javascript `location.href` might help. – Chay22 Apr 09 '16 at 04:51
  • @Chay22 - Thanks for the solution . can you insert the mentioned code in this script ? I know little about js – Shijil T Apr 09 '16 at 05:08

1 Answers1

0

The server can't set HTTP referrer to the client. Use javascript instead

Change

header("Location: {$urls[$id]}");

to

echo "<script>location.href = '".$urls[$id]."';</script>";

Suit yourself to get other javascript types redirection here

Community
  • 1
  • 1
Chay22
  • 2,834
  • 2
  • 17
  • 25