Welcome Guest, Not a member yet? Register   Sign In
Another alternative for redirect() ?
#1

[eluser]stevefink[/eluser]
Or perhaps I need to re-think my logic here.

I have some code which looks like this:

Code:
function index()
    {
        $this->load->library('Erkanaauth');
        $this->load->library('validation');
        
        /* validation rules for login form */
        $rules['email'] = "trim|required|valid_email|xss_clean";
        $rules['pass'] = "trim|required|xss_clean|md5";
        $this->validation->set_rules($rules);
        
        if($this->validation->run() == FALSE) {
            $this->session->sess_destroy();
            $this->load->view('login_view');
        } else {
            redirect('/foo/', refresh);
        }
        
    }

However, when I try to redirect() here upon successful login, I get complaints that I cannot modify header information as headers have already been sent to the browser. Sort of confused here. Would appreciate any hints. :-)
#2

[eluser]stevefink[/eluser]
I can alternatively use $this->load->view(), however that requires me to duplicate code, which is a shame. I need code to pull data from the database which I already have set in a separate controller. It would be nice to redirect to there instead of copy/pasting the code into the $this->validation->run() clause.
#3

[eluser]tonanbarbarian[/eluser]
I cannot see anything obvious as to why the headers have already been sent.
I would try
Code:
redirect('/foo/');
To see if that makes any difference.
apart from that see if you can work out what is sending header information before the redirect
unless you are autoloading something the only thing I can think of is if one of your files has blank space before the opening <?php tag
#4

[eluser]stevefink[/eluser]
I'm not sure why it's happening either. The -only- thing I can possibly think of, is I post the form to itself. Instead of using say &lt;form action="&lt;? $_SERVER['PHP_SELF']" ..&gt; I'll use something like <form action="&lt;?base_url()?&gt;login" which is the origin of the form..

Does that make sense?
#5

[eluser]tonanbarbarian[/eluser]
try using site_url('login');

cannot see how that is going to solve the problem though but try it
#6

[eluser]Michael Wales[/eluser]
Nope - I always submit the form to itself, and redirect upon a successful processing.

I'm thinking you may have white-space somewhere...
#7

[eluser]tonanbarbarian[/eluser]
I would check what you are autoloading
Also check to make sure your PHP is not prepending anything
php.ini look for auto_prepend_file and make sure it is not set
#8

[eluser]gtech[/eluser]
Hi I nearly always get this sort of error when I have either:

A space outside the &lt;?php ?&gt; tags, If this is the case a space gets sent to the browser and of course the headers get set up before the redirect.

OR

I Have echoed/print_r'd content anywhere before the redirect.

One thing you can do is check to see there are no white spaces outside the &lt;?php ?&gt; tags of the controller.. and then if thats not the problem check the libraries you are calling, did you put any echos/print_r's for debug purposes inside the libraries? are there spaces out side the tags?
#9

[eluser]stevefink[/eluser]
Thanks for the reply and help folks.

Yeah it was determined that I had an extrenuous space at the end of one of my models. Completely could NOT see it with the naked eye.

It would be nice of the PHP compiler can be hacked to eradicate all white spaces after the last ?&gt; in a file.

I wonder how badly I'd break things by trying to edit the PHP source myself to do this. I mean, it already gets rid of comments during compilation, does it not?
#10

[eluser]Grahack[/eluser]
Hi, you can forget the closing php tags (see here).
So you're sure not to have white space after it Wink.




Theme © iAndrew 2016 - Forum software by © MyBB