How can i do a redirect pre-systme hook ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How can i do a redirect pre-systme hook ? (/showthread.php?tid=49406) |
How can i do a redirect pre-systme hook ? - El Forum - 02-18-2012 [eluser]bhenbe[/eluser] Hi all, for an unknown reason, a redirect in a pre_system hook doesn't work. It's the first time i try this. I need to redirect some urls if they are listed in a database. So, something like http://www.mysite.com/code-igniter can be a redirect and not a controller. Here's my code : Config hook : Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Hook Direct_access : Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I changed the return code by an echo to check each part of my code. Nothing's wrong but the Header function doesn't work. CI always show me a 404 page because the controller doesn't exist. Anyone have an idea ? Thanks ! How can i do a redirect pre-systme hook ? - El Forum - 02-18-2012 [eluser]toopay[/eluser] Change Code: Header('Location: '.$row['redirect']); Code: header("Location: $row['redirect']"); How can i do a redirect pre-systme hook ? - El Forum - 02-18-2012 [eluser]bhenbe[/eluser] Thanks ! You must also check if $row doesn't return false. Without this check, exit will stop the controller calls. Code: $query = sprintf("SELECT `redirect` FROM `direct_access` WHERE `url` LIKE '%s'", mysql_real_escape_string($url)); |