Created
June 19, 2018 02:36
-
-
Save camiloibarrayepes/481003098a97fa67f03f39d78d9f7a73 to your computer and use it in GitHub Desktop.
Redirect php url friendly getting id and showing name or username
This file contains hidden or 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
| RewriteEngine On | |
| Options +FollowSymLinks | |
| #Allow '-' and letters/numbers | |
| RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9-]+)$ b_user.php?view=$1&name=$2 | |
| RewriteRule ^([a-zA-Z0-9]+)$ b_user.php?view=$1 | |
| RewriteRule ^([^\.]+)$ $1.php [NC,L] |
This file contains hidden or 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 | |
| $id=$_GET['id']; | |
| $name=$_GET['name']; | |
| $name = str_replace('-', ' ', $name); | |
| $query = "SELECT * FROM bussiness_user WHERE nombre = '$name'"; | |
| while($row2 = $resultado2->fetch_assoc()) | |
| { | |
| //capture necessary data | |
| $phone=$row2['phone']; | |
| } | |
| ?> |
This file contains hidden or 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 | |
| include('logic/conexion.php'); | |
| $id=$_GET['id']; | |
| $query = "SELECT * FROM bussiness_user WHERE id = '$id'"; | |
| $resultado2 = $link->query($query); | |
| while($row2 = $resultado2->fetch_assoc()) | |
| { | |
| $nombre=$row2['nombre']; | |
| } | |
| function urls_amigables($url) { | |
| // Tranformamos todo a minusculas | |
| $url = strtolower($url); | |
| //Rememplazamos caracteres especiales latinos | |
| $find = array('á', 'é', 'í', 'ó', 'ú', 'ñ'); | |
| $repl = array('a', 'e', 'i', 'o', 'u', 'n'); | |
| $url = str_replace ($find, $repl, $url); | |
| // Añaadimos los guiones | |
| $find = array(' ', '&', '\r\n', '\n', '+'); | |
| $url = str_replace ($find, '-', $url); | |
| // Eliminamos y Reemplazamos demás caracteres especiales | |
| $find = array('/[^a-z0-9\-<>]/', '/[\-]+/', '/<[^>]*>/'); | |
| $repl = array('', '-', ''); | |
| $url = preg_replace ($find, $repl, $url); | |
| return $url; | |
| } | |
| echo $nombre_ns = urls_amigables($nombre); | |
| //$nombre_ns = str_replace(' ', 'x', $nombre); | |
| ?> | |
| <!-- Redirect to b_user.php with the variables --> | |
| <script> | |
| window.location.replace("profile/<?php echo $nombre_ns; ?>"); | |
| /*window.location.replace("b_user.php?view=profile&name=<?php echo $nombre ?>");*/ | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment