重定向到另一个 URL,将其写入自己的 URL 中



很可能这是不可能的,但我想问一下,以防万一。

我有一个数据库,其中保存了一些数字(1,2,3...(。

我有一个.php页面,我从中阅读数字。 我将这些数字连接到一个字符串以获取完整的 URL。 例如:

$intArticle = $row["article"];
$strURLBase = "example.com/index.php/"
$strLink = $strURLBase . $intArticle;
//And I get "example.com/index.php/1"

但是现在,有一个例外,其中URL指向外部网站,所以我的代码暂时无效。

我知道如何在.php中修复它,但我想知道是否可以直接在 URL 中进行重定向,将正确的字符串保存在数据库中。 例如:

$intArticle = $row["article"];  //In this case, the value of $row["article"] could be, for example, "http://www.externalweb.com"
$strURLBase = "example.com/index.php/"  //This part should be ignore inside the URL
$strLink = $strURLBase . $intArticle;
//I would get "example.com/index.php/http://www.externalweb.com"

我可以在 URL 中编写任何类型的指令(我会保存到数据库中,然后我会连接到$strURLBase(重定向到另一个 URL? 例如:

example.com/index.php/!$%&_redirec_to("http://www.externalweb.com")

我不想从重定向的 URL 调用任何 PHP 函数。 事实上,任何PHP代码都不应该被执行。 所有内容都应在 URL 内。

试试这个:

if (!is_numeric($intArticle))
{
header("Location: ".$strLink."");
exit;
}
// your site will continue here, if the article is a number

最新更新