之前会显示消息的“多个重定向"页面,这是最好的方法吗? [英] Multiple Redirect page that would display a message before, is this the best method?

查看:96
本文介绍了之前会显示消息的“多个重定向"页面,这是最好的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个约有50个页面的网站,每个页面都有一个文本链接和一个横幅链接,
我希望他们引导到相同的重定向页面,该页面会将他们重定向到外部URL,
根据这些横幅/文本链接中的两个变量.

I have a website with about 50 pages, each one have a text link and a banner link,
I want them to lead to the same redirect page, that would redirect them to an external URL,
according to two variables that would be in these banner/text link.

横幅链接类似于:

http://mydomain.com/redirect.php?dest=2&source=banner

这里的代码似乎有效,我不是程序员,所以我只是从这里到那里编译补丁.

Here's a code that seems to be working, I'm not a programmer so I've just compiled patches from here and there.

<!doctype html>
<?php

$id = $_GET['source']; // user would get to this page with an "id" that would be according to the link he clicked, either text or banner; this "id" info needs to be passed on to the external page as well, with the following "?referal" tag.

if(isset($_GET['dest'])); // user would get to this page from one of about 50 different pages; his redirect destination would depened on the "dest" number of the link he clicked

switch ($_GET['dest']) {

    case "1":
        $url = "http://url1.com/?referal=$id";
        break;

    case "2":
        $url = "http://url2.com/?referal=$id";
        break;

    case "3":
        $url = "http://url3.com/?referal=$id";
        break;

    default:
        $url = "http://unknown.com/?referal=$id";
}

?>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="5;url=<?php print $url; ?>">
<title>Untitled Document</title>
</head>

<body>


<?php
$id = $_GET['source'];
if ($id == 'text'){
    echo 'The clicked link was a text link';
}
elseif ($id == 'banner'){
    echo 'The clicked link was a banner link';
}
else {
    echo 'The clicked link is unknown';
}
?>

<p></p>

<?php
if(isset($_GET['dest']));

switch ($_GET['dest']) {

    case "1":
        $url = "http://url1.com/?referal=$id";
        echo "You would be redirected to domain no. 1";
        break;

    case "2":
        $url = "http://url2.com/?referal=$id";
        echo "You would be redirected to domain no. 2";
        break;

    case "3":
        $url = "http://url3.com/?referal=$id";
        echo "You would be redirected to domain no. 3";
        break;

    default:
        echo "default";

}
 ?>  

 <P></P>
 <?php
 echo "The url you would be redirected to is: $url";
  ?>  

</body>
</html>

我想知道-这是用于此目的的最佳代码吗?另外,即使我希望页面显示一些数据,是否也可以使用PHP而不是META进行重定向?

I want to know - Is this the optimal code for the purpose? also, Is it possible to make the redirect with PHP instead of META, even though I want the page to display some data?

推荐答案

在此处进行测试: https://eval.in/83122

应该可以.我已经测试过:

It should work. I have tested it:

  <!doctype html>
    <?php

    $id = $_GET['source']; // user would get to this page with an "id" that would be according to the link he clicked, either text or banner; this "id" info needs to be passed on to the external page as well, with the following "?referal" tag.

    if(isset($_GET['dest'])){ // user would get to this page from one of about 50 different pages; his redirect destination would depened on the "dest" number of the link he clicked

    switch ($_GET['dest']) {

        case "1":
            $url = "http://url1.com/?referal=$id";
            break;

        case "2":
            $url = "http://url2.com/?referal=$id";
            break;

        case "3":
            $url = "http://url3.com/?referal=$id";
            break;

        default:
            $url = "http://unknown.com/?referal=$id";
    }

    }

    ?>
    <html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="refresh" content="5;url=<?php print $url; ?>">
        <title>Untitled Document</title>
    </head>

    <body>


    <?php
    $id = $_GET['source'];
    if ($id == 'text'){
        echo 'The clicked link was a text link';
    }
    elseif ($id == 'banner'){
        echo 'The clicked link was a banner link';
    }
    else {
        echo 'The clicked link is unknown';
    }
    ?>

    <p></p>

    <?php
    if(isset($_GET['dest'])){

    switch ($_GET['dest']) {

        case "1":
            $url = "http://url1.com/?referal=$id";
            echo "You would be redirected to domain no. 1";
            break;

        case "2":
            $url = "http://url2.com/?referal=$id";
            echo "You would be redirected to domain no. 2";
            break;

        case "3":
            $url = "http://url3.com/?referal=$id";
            echo "You would be redirected to domain no. 3";
            break;

        default:
            echo "default";

    }

    }
    ?>

    <P></P>
    <?php
    echo "The url you would be redirected to is: $url";
     //header("location".$url); //enable it to redirect to the $url
    ?>

    </body>
    </html>

这篇关于之前会显示消息的“多个重定向"页面,这是最好的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆