【发布时间】:2022-01-23 16:03:54
【问题描述】:
请帮助我弄清楚如何处理来自链接的重定向,如下所示: http://link.site.com/636337 到 http://new.site.com/index.php?param=202020
注意域是根据ID从数据库中选择的(http://link.site.com/636337 636337是这里的ID),它指向域http://new.site.com/index.php
我要做的就是将参数添加到域中以成为http://new.site.com/index.php?param=202020
感谢您的帮助将受到高度重视和赞赏。
这是我的代码:
include "inc/config.php";
if(!isset($_GET["id"])) {
addLog(1);
http_response_code(404);
exit("<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>");
}
$getid = $pdo->prepare("SELECT id FROM links WHERE uniq_id = :id");
$getid->bindParam("id", $_GET["id"]);
$getid->execute();
if($getid->rowCount() == 0) {
addLog(1);
http_response_code(404);
exit("<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>");
}
$id = $getid->fetch()["id"];
// Only select 10 domains for performance
$getdomains = $pdo->prepare("SELECT * FROM domains WHERE link_id = :id AND status = 0 LIMIT 10");
$getdomains->bindParam("id", $id);
$getdomains->execute();
$domains = array();
if($getdomains->rowCount() == 0) {
http_response_code(404);
exit("<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>");
}
foreach ($getdomains->fetchAll() as $domain) {
$domains[] = $domain["link"];
}
//Redirect to first url to the link with parameter value $paramid
if(empty($domains)) {
http_response_code(404);
exit("<html><head><title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL was not found on this server.</p></body></html>");
}
$paramid = "20202020";
$urls = $domains[0];
//echo($urls);
header("Location: ".$url."?email=".$paramid); ```
The Problem is, it redirects only to the domain http://new.site.com/index.php but without the parameters
【问题讨论】:
-
它现在如何工作/不工作?您能否举例说明您收到的错误或当前的行为方式?
-
您是在问如何构建链接,或使重写工作?
-
它只重定向到域new.site.com/index.php,但没有参数
-
我看到的唯一重定向是
header("Location: ".$url."?email=".$paramid);,你期望?email=如何神奇地变成?param=,但目前最多只有你知道的秘密。
标签: php