Welcome Guest, Not a member yet? Register   Sign In
header (Location..) not working.
#1

[eluser]hugle[/eluser]
Hello everyone.

I'm really glad that there is such a nice framework.
Really nice product.

I'm currently fighting with a Controller..

I don't get, what I do wrong,

here is my controllers.switchpotw.php file:

<?php

class switchpotw extends Controller {

function switchpotw()
{
parent::Controller();
$this->output->cache(0);
}

function page()
{
$numrows = $this->db->GetOne("SELECT COUNT(id) AS numrows FROM potw");

$page = $this->uri->segment(3);

if($page <= $numrows) {
$_SESSION['potw-pagenr'] = $page;
} else {
$_SESSION['potw-pagenr'] = 1;
}


header("Location: /");

}

}
?&gt;

I don't Understand, why would header won't work here?
If I try to eho some data there - it is ok.
Any help is appreciated!

Thanks everyone for any suggestions!

cheers,
Jaroslav
#2

[eluser]taewoo[/eluser]
it would help if you explained what you're trying to do.

PS: Don't set session variables manually... look at the DB_Session class.
#3

[eluser]hugle[/eluser]
[quote author="taewoo" date="1226025349"]it would help if you explained what you're trying to do.

PS: Don't set session variables manually... look at the DB_Session class.[/quote]

I will try:

so I have main page with Flash slideshow.
This slideshow takes users "id" from database.

so I have done a Html link to: /switchpotw/page/2

so it calls the controller, and sets session data ($_SESSION['potw-pagenr']) = 2.

And forwards back to main page ( / )
How the flash slideshow player reads data of users id number 2
etc...

the controller itself works okay.
if I echo echo $page; = it gives proper results.

But header () thing does not work..

Thanks for your time!
#4

[eluser]ray73864[/eluser]
I assume you are trying to use the 'header(Location: )' if that is the case, take a look at the CI function 'redirect()', it is in the URL helper class i believe. basically it goes like: redirect("<url>"[,true|false]);
#5

[eluser]hugle[/eluser]
[quote author="ray73864" date="1226027235"]I assume you are trying to use the 'header(Location: )' if that is the case, take a look at the CI function 'redirect()', it is in the URL helper class i believe. basically it goes like: redirect("<url>"[,true|false]);[/quote]

Hello Ray.

I have just looked into it, but it seems not to work for me somehow ...

I have tried this variations:
redirect('/', 'location');
redirect('/', TRUE);
redirect('/', FALSE);

I believe 1st variant should work, but insead of beeing forwarded I get "white" screen.

Can't understand what I'm doing wrong..

Maybe I need a viewer for such combination?
#6

[eluser]ray73864[/eluser]
the redirect() function redirects to a controller and not to a view, and since you don't seem to have an 'index()' function defined, i think it will just give you a blank page instead of an error message.
#7

[eluser]hugle[/eluser]
[quote author="ray73864" date="1226057684"]the redirect() function redirects to a controller and not to a view, and since you don't seem to have an 'index()' function defined, i think it will just give you a blank page instead of an error message.[/quote]

good suggestion, but it seems not to work either, now the controller looks like:

&lt;?php

class switchpotw extends Controller {

function switchpotw()
{
parent::Controller();
// $this->output->cache(0);
}

function index()
{
echo 'index page here';
}

function page()
{
$numrows = $this->adodb->GetOne("SELECT COUNT(id) AS numrows FROM potw");

$page = $this->uri->segment(3);

if($page <= $numrows) {
$_SESSION['potw-pagenr'] = $page;
} else {
$_SESSION['potw-pagenr'] = 1;
}

// echo $page;
redirect('index', 'location');

}

}
?&gt;

I get blank page, while accessing:
example.com/switchpotw/page/2
if I comment out the "echo" line in function `page`
I get "2"

No redirect happens..

Thought it could be because of cache, disabled it by commenting out..

still same problem. I don't get it ...
#8

[eluser]jadebot[/eluser]
how about setting up a completely new controller and testing redirect from scratch.

So basically create new controller called "test" in the index function of "test" first echo some results.
If that works, place your header redirect there and redirect to "test/redirect" where redirect is another
function within the test controller and echo something like "redirect has worked".

Then you call test controller again and you should get "redirect has worked".

This would be the most simple case so if you get this to work, you can build it from there. If this does not work then something is
wrong with your CI installation or configuration.

Code:
class Test extends Controller {

  function Test()
  {
    parent::Controller();
  }
  
  function index()
  {        
       header("Location: /test/redirect");
  }

  function redirect()
  {        
       echo 'redirect has worked!!';

  }
  
}
#9

[eluser]hugle[/eluser]
Hello jadebot,

I don't know what I am doing wrong, but as you suggested:
I have controller called test.php with content:

Code:
&lt;?
class Test extends Controller {

    function Test()
    {
        parent::Controller();
    }

    function index()
    {        
//       header("Location: /test/redirect");
        echo "index here";
    }

    function redirect()
    {        
       echo 'redirect has worked!!';

    }
  
}
?&gt;

I I try to access /test directry by www.example.com/test/ - everything I get "index here"

If I try to accesss example.com/test/redirect -I get "redirect has worked!!"

But if I change index function to :

Code:
function index()
    {        
       header("Location: /test/redirect");
    }
I just get blank page. Maybe I should load some libraries ?

Still needing help, can't figure it out

Thanks for you time!

cheers,
Jaroslav
#10

[eluser]jadebot[/eluser]
That test should work out of the box. Maybe try it on a separate/fresh install of CI. I just tried it and it works fine for me. As I said, its the bare simple test, so if that does not work, something is wrong in CI or maybe your server or something ... is this on a live site or development? Anyone know if hosting providers can disable header calls?? Something is definitely up, the test should work.

You should be getting "redirect has work" when you call www.example.com/test




Theme © iAndrew 2016 - Forum software by © MyBB