提问者:小点点

将参数从另一个页面发布到url


请告诉我如何处理来自链接的重定向,我需要帮助,如下所示:http://link.site.com/636337到http://new.site.com/index.php?param=202020

注意:域是根据ID从数据库中选择的(http://link.site.com/6363376337是这里的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 

共1个答案

匿名用户

这很可能是打字错误。检查PHP代码的结尾:

$paramid = "20202020";
$urls = $domains[0];
//echo($urls);

header("Location: ".$url."?email=".$paramid);

您可以创建变量$url,但可以使用$url作为位置标头$url没有在任何地方定义,因此我假设它在这里是一个空变量
写入$url=$domains[0]取而代之。

请记住,位置标题立即起作用。因此,echo这里应该跟在exit后面,以便进行调试。

我建议您将位置值设置为一个变量,这样您也可以轻松地回显它:

$url = $domains[0];
$location = $url . '?email=' . $paramid;
// echo $location; exit;

header("Location: " . $location);

让自己调试更简单总是值得的。