Skip to content

Instantly share code, notes, and snippets.

@gubi
Last active December 26, 2015 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gubi/7111875 to your computer and use it in GitHub Desktop.
Save gubi/7111875 to your computer and use it in GitHub Desktop.
This script finds searched pages to similar existing and redirect users to correct page if the result is 1. Use PDO connection.
<?php
$page = addslashes($_GET["p"]);
$searching_page = $pdo->query("select * from `TABLE` where `COLUMN` sounds like '%" . $page . "%'");
if($searching_page->rowCount() == 1) {
while($dato_searching_pages = $searching_page->fetch()) {
header("Location: " . $dato_searching_pages["COLUMN"]);
exit();
}
} else {
$searching_page = $pdo->query("select * from `TABLE` where `COLUMN` sounds like '%" . $page . "%'");
if($searching_page->rowCount() > 1) {
$content_page = "<section><p>The page you're looking for do not exists :(<br />Maybe you're looking for:</p><ul>";
while($dato_searching_pages = $searching_page->fetch()) {
$content_page .= '<li><a href="./' . $dato_searching_pages["COLUMN"] . '">' . $dato_searching_pages["COLUMN"] . '</a></li>';
}
$content_page .= "</ul></section>";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment