Welcome Guest, Not a member yet? Register   Sign In
redirect() throwing a blank page, while header() works
#1

[eluser]Ki[/eluser]
Does anybody have a clue why would header() function work, while CI's redirect() is throwing a blank page. I have observerd it across various controllers. I even tested this right in my main controller, at the very beginning of the code.
Checked logs and error reporting with no result. I am almost 100% sure that nothing is showing up before the headers...

This is my main controller
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

define('HOST1', $_SERVER['HTTP_HOST']);
define('LOGO', 'http://img1.domain.com/logo/logo_v1_bg.gif');

class  MY_Controller extends Controller{

    function __construct(){
        parent::__construct();
        $this->setup_assets();
    }
        
    function setup_assets(){
            //$this->output->enable_profiler(TRUE);
            //$this->benchmark->mark('my_controller_start');

        if(!isset($this->data['url_array'])) $this->data['url_array'] = $this->uri->uri_to_assoc(2);
        
        //redirect for deleted categories
        $this->data['controller'] = $this->uri->segment(1);
                $redirect_cat_array=array(
                    105=>199,
                    106=>199,
                    210=>299,
                    408=>499,
                    503=>502,
                    504=>502,
                    505=>502,
                    705=>799,
                    806=>899,
                    907=>999,
                    1008=>1099,
                    1108=>1199,
                    1209=>1299,
                    1608=>1699,
                    1609=>1699,
                    1305=>1399,
                    1306=>1399
                );
        if( isset($this->data['url_array']['catid']) && isset($redirect_cat_array[$this->data['url_array']['catid']]) ){
            $redirect_link = str_replace('catid/'.$this->data['url_array']['catid'],'catid/'.$redirect_cat_array[$this->data['url_array']['catid']],$_SERVER['REQUEST_URI']);
            //redirect($redirect_link);
                        header("Location:".$redirect_link,TRUE,301);
        }

NOtice above I comented out the redirect() function, because if I enable it and remove header function - I will get a blank page.
#2

[eluser]Phil Sturgeon[/eluser]
Are there any errors showing up? Check your CodeIgniter logs to see if anything nuts is happening.

Where are you loading url_helper?
#3

[eluser]Ki[/eluser]
No errors show up, CI logs are empty (yeah - I try to keep on top of all the little issues and errors, so the logs usually are clean)
URL helper is loaded with autoload
What I can't get my head around is WHY is header() working and not redirect()? Are they not same behavior?
Is there a way to trace whats happeneing:

By the way, I did PAGE SOURCE for the blank page and this is what I see:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&lt;HTML&gt;&lt;HEAD>
&lt;META http-equiv=Content-Type content="text/html; charset=utf-8"&gt;
&lt;META content=CMVRDPEJHO name=SKYPE_FRAMEID&gt;&lt;/HEAD>
&lt;BODY&gt;&lt;/BODY>&lt;/HTML&gt;
#4

[eluser]Flemming[/eluser]
what do you get if you echo out
Code:
$redirect_link
?
#5

[eluser]Ki[/eluser]
Unfortunatly redirect() does not work even if the link is hardcoded, such as:
Code:
redirect('account/logout');


Thanks for the suggestion :-S
#6

[eluser]Unknown[/eluser]
Hello,

I encountered the same problem. After deactivating xdebug, everything was working again. (well, I admid my xdebug installation is php_xdebug-2.1.0beta1-5.3-vc9.dll)

greetz
#7

[eluser]theprodigy[/eluser]
what type of server are you using (linux, windows, mac, etc)?

have you tried setting the second optional parameter?

Code:
redirect($redirect_link, 'refresh'); // if using Windows, the 'refresh' is needed

also, I see you are setting the header to a 301 redirect. Why not set the redirect to the same thing?

Code:
redirect($redirect_link, 'refresh', 301);
//or
redirect($redirect_link, 'location', 301); //may be faster, but don't use on a Windows server
#8

[eluser]zool2005[/eluser]
[quote author="Phil Sturgeon" date="1258038024"]Where are you loading url_helper?[/quote]

That did it for me.
I was starting a new project and completely forgot to autoload this helper !




Theme © iAndrew 2016 - Forum software by © MyBB