|
-
May 24th, 2006, 06:08 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Redirection Blues
Hi,
I'm new at PHP and I'm having to learn it through the crash course method. I'm having difficulties with redirecting to another page.
I've read that you have to use the
PHP Code:
header('Location:http://website/page');
But everytime I do I get this error message
Warning: Cannot modfy header information - headers already sent by (output started at c:\Inetpub\wwwroot\test1.php:2) in c:\Inetpub\wwwroot\test1.php on line 4
I read about this error and it seems that therer are a dozen PHP codes and HTML tags that you cannot have before the header function. This seems awefully restrictive. Is there another better way to redirect?
Changes are not permanent, but change is. {Neil Peart}
-
May 24th, 2006, 06:11 PM
#2
<?="Moderator"?>
Re: Redirection Blues
You cannot have any thing printed out before you call the header function, if you do the header function will throw the warning that you get. Go though your code and make sure that the re-direct is the first thing that is printed out.
If you want to display a message before you redirect the user then you will have to use a cominable of meta tags and/or javascript.
-
May 24th, 2006, 07:10 PM
#3
Thread Starter
Addicted Member
Re: Redirection Blues
Wow, that sounds like a huge undertaking. As my first web development project, I always assumed that my overall structure would be shoddy and that I'd get slammed somewhere. I think it can be done though with some medium overhauling. I'll give it a try.
Changes are not permanent, but change is. {Neil Peart}
-
May 24th, 2006, 07:37 PM
#4
<?="Moderator"?>
Re: Redirection Blues
 Originally Posted by kzatu
Wow, that sounds like a huge undertaking. As my first web development project, I always assumed that my overall structure would be shoddy and that I'd get slammed somewhere. I think it can be done though with some medium overhauling. I'll give it a try.
Whilst your reworking your code try to keep in mind
- Keep your Logic sperate from your display
- Avoid using print or echo to display chunks of html, search the forum for better methods
- check any values that are being passed via from using isset and check for unwanted HTML characters
-
May 25th, 2006, 10:02 AM
#5
Thread Starter
Addicted Member
Re: Redirection Blues
Well I tried a little test before I started changing my structure. The first four lines in my index.php are this:
PHP Code:
<?
session_start();
require('functions.php');
dbconnect();
So I started testing by inserting header('Location:http://website/test.php'); after session_start and before require('functions.php');, and that worked. Next I placed it after require and before dbconnect and the redirect failed.
Every line of code in the functions.php is inside of a function. So simply requiring functions.php does not execute any code in that script. So next I began moving my header redirect line throughout the functions.php all the way down to the very last PHP closing tag ?>. And the redirect still worked.
So it seems that requiring (or including) another PHP script, that has no prints, still disables the header redirect.
Any ideas?
Changes are not permanent, but change is. {Neil Peart}
-
May 25th, 2006, 10:04 AM
#6
Re: Redirection Blues
Make shure there are no spaces or newlines after the closing ?> in functions.php. Any characters outside <? and ?> will be outputted.
-
May 25th, 2006, 10:11 AM
#7
Thread Starter
Addicted Member
Re: Redirection Blues
Wow. Thanks for the lightning fast response. Also you were correct. I had a CRLF after the ?>. This is going to make me paranoid now.
Changes are not permanent, but change is. {Neil Peart}
-
May 25th, 2006, 10:14 AM
#8
Re: Redirection Blues
Heheh 
After a while you get used to just putting in <?php and ?> when you make a new backend file and working between those.
-
May 25th, 2006, 10:15 AM
#9
<?="Moderator"?>
Re: Redirection Blues
In your include file make sure you dont have any white space before the opening <? tag, it can be simple a space or a newline, but check through your include to make sure. 9/10 times its something simple.
Read this post it will help you get your head aroudn debugging PHP and just good practice.
http://www.vbforums.com/showpost.php...74&postcount=6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|