direct page with header

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
motiksir
Forum Newbie
Posts: 15
Joined: Sat Oct 22, 2011 5:33 pm

direct page with header

Post by motiksir »

i want that the page direct to another page..
in the wamp it work but in server not
what the problem?

this my code:

Code: Select all

header('Location:/displayImages.php');
its stay in the page that write the header..

what to do?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: direct page with header

Post by twinedev »

You have to make sure there is no output before the header statement, including spaces or blank lines ( <?php needs to be first character in the file.

Also check the source code, on you xamp server, you may have warnings disabled from showing, but on the live server they are displaying, and you may have something generating a warning or notice, yet it is in a place on the page that you are not seeing it, but will see it at the top of the View->Source for the page.

Lastly, make sure you always add an exit; statement after a header redirect. I even do this if it is at the end of the file, just in case later some thing else gets added.

-Greg
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: direct page with header

Post by thinsoldier »

Everything twinedev said.

Also for me it's the other way around with wamp on my laptop. I can have up to 71 characters of output before using header and it works on my laptop.
On my old php4 server I would let me get away with 90 characters of output and header would still work.
When I got a new php5 server of course everything broke!

Best thing to do is exactly what twindev said. Especially calling exit() after header(). If you're using an MVC and all your "pages" are actually triggered by functions you might accidentally write return; out of habit instead of exit. Double check. Always call exit after a header().
Warning: I have no idea what I'm talking about.
Post Reply