Welcome Guest, Not a member yet? Register   Sign In
Redirect Function with custom delay
#1

[eluser]Yash[/eluser]
I've added a fourth parameter.If you want to redirect on other url after sometime just use this parameter.You can pass any time delay value.
Not BIG deal in this but can cause problem sometime.
Code:
<?php

if ( ! function_exists('redirect'))
{
    function redirect($uri = '', $method = 'location', $http_response_code = 302,$time=0)
    {
        switch($method)
        {
            case 'refresh'    : header("Refresh:$time;url=".site_url($uri));
                break;
            default            : header("Location: ".site_url($uri), TRUE, $http_response_code);
                break;
        }
        exit;
    }
}

?>

Replace this function with your system/helper/url_helper.php function.
#2

[eluser]sophistry[/eluser]
[quote author="Yash" date="1217111642"]
Replace this function with your system/helper/url_helper.php function.[/quote]

@yash,

first of all, thanks for the code contribution! it's great to see a nice variation on the redirect. i've found that certain browsers react differently to the meta refresh tag and i'm sure there is a page or two on it somewhere out there.

second, the ideal way to use a helper modification such as this one is to put it in its own file inside application/helpers directory and call the file MY_url_helper.php ... see the manual for details. do not replace (copy/paste) functions into the core files, it's just bad practice.

that way, this (same named) function can override the old one (but, you might have to remove the function exists check - not completely sure on that point). makes for better portability and easier upgrading to new core versions.

cheers.
#3

[eluser]Pascal Kriete[/eluser]
Sophistry has said it all (as always) :coolsmile: .

[quote author="sophistry" date="1217145464"](but, you might have to remove the function exists check - not completely sure on that point)[/quote]

No, no, that's what makes overriding possible. The MY_Helper files are loaded first - the function_exists check makes sure the overridden functions aren't re-declared. PHP doesn't allow for two functions with the same name (in the same scope).
#4

[eluser]Colin Williams[/eluser]
CI's core helpers do the check so your own helpers don't have to. So yes, you CAN remove the function_exists() check.
#5

[eluser]Yash[/eluser]
yea I know we can make our own library.But even you replace it wth core doesn't make any difference in calling redirect.

But yes I agree
Quote:second, the ideal way to use a helper modification such as this one is to put it in its own file inside application/helpers directory and call the file MY_url_helper.php ... see the manual for details. do not replace (copy/paste) functions into the core files, it’s just bad practice.


it seems I forget to mention this point.anyways you catch it.
#6

[eluser]Pascal Kriete[/eluser]
Thanks for clarifying Colin, I meant to say: don't remove it from the core files.




Theme © iAndrew 2016 - Forum software by © MyBB