Please I need help figuring out how to handle a redirect from a link as this: http://link.site.com/636337 to http://new.site.com/index.php?param=202020
Note the domain is selected from database based on the ID (http://link.site.com/636337 636337 is the ID here) and it points to domain http://new.site.com/index.php
All am trying to do is add the parameters to the domain to become http://new.site.com/index.php?param=202020
Thanks as your help would be higly regarded and appreciated.
here is my code:
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
CodePudding user response:
This is most likely a typo. Check the end of your PHP code:
$paramid = "20202020";
$urls = $domains[0];
//echo($urls);
header("Location: ".$url."?email=".$paramid);
You create the variable $urls
, but you use $url
for the Location header. $url
is not defined anywhere, so I assume it is an empty variable here.
Write $url = $domains[0];
instead.
More debugging
Keep in mind that a Location
header works immediately. So echo
here should be followed by exit for your debugging purposes.
I would suggest you make the location value a variable so you can echo it easily as well:
$url = $domains[0];
$location = $url . '?email=' . $paramid;
// echo $location; exit;
header("Location: " . $location);
Help yourself debug easier is always worthwhile.