Created
August 10, 2019 13:53
-
-
Save eriktonon/3a205962b24566aced19bb9caf56652a to your computer and use it in GitHub Desktop.
encurtador
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$config = json_decode(file_get_contents('../config.json')); | |
$pdo = new \PDO( | |
sprintf( | |
'pgsql:host=%s;port=%s;dbname=%s', | |
$config->banco->host, | |
$config->banco->port, | |
$config->banco->database | |
), | |
$config->banco->user, | |
$config->banco->pass | |
); | |
$url = $_SERVER['REDIRECT_URL']; | |
$url = explode('/', $url); | |
$url = end($url); | |
$stmt = $pdo->prepare('select urlprincipal from gazin.encurtador_url where url = :url'); | |
$stmt->bindValue(':url', $url); | |
if (!$stmt->execute()) { | |
print_r($stmt->errorInfo[2]); | |
exit; | |
} | |
$redirecionar = $stmt->fetch(\PDO::FETCH_OBJ); | |
if (!$redirecionar) { | |
http_response_code(404); | |
exit; | |
} | |
header('Location: ' . $redirecionar->urlprincipal); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment