|
-
Feb 14th, 2005, 06:07 PM
#1
Re: Header crap. Give me response.redirect anyday.. Can you turn me back?
I'm going to takle your questions in reverse.
First why the cannot send headers info: 1) Make sure there is NOT BLANK lines or anything at the top. Even a single whitespace is considered output. Secondly, the error generated by line resulted in output (the error msg). So Once you get that straightended out, it should go away.
Ok, now for the error on line 2. You really should check to see if the $_GET[] is set first:
Code:
if (isset($_GET["action"])) {
$Action = $_GET["action"];
}else{$Action='';}
Then use $Action in your switch:
Code:
switch ($Action) {
case "auth":
echo "you are at auth";
break;
case "sum":
echo "you are at sum";
break;
case "phpinfo":
phpinfo();
break;
default:
header( 'location:http://localhost:1987/php_dev/index.php?action=auth' );
exit;
}
?>
To attempt to access it w/o first making sure it's there is akin to acessing an object before instanciating it.
Tg
-
Feb 14th, 2005, 06:24 PM
#2
Thread Starter
Addicted Member
Re: Header crap. Give me response.redirect anyday.. Can you turn me back?
ok, you may of pulled me back to PHP.
One question is;
is there a redirect command that can me used at any point?
The Response.Redirect command is useable at anytime. Is there one for PHP
-
Feb 14th, 2005, 06:56 PM
#3
Re: Header crap. Give me response.redirect anyday.. Can you turn me back?
 Originally Posted by DigitalMyth
ok, you may of pulled me back to PHP.
One question is;
is there a redirect command that can me used at any point?
The Response.Redirect command is useable at anytime. Is there one for PHP
Yes and no. Firstly it is best to have a redirect at the top of your script before any output as it makes the code more readable to other developers.
Should the need still arise to send a header after output has been sent you can use output buffering. An output buffer is a place where all output from the script is held until the script is done executing. Once the script has finished the buffer is flushed and all the data is sent to the client in one big chunk.
To turn on the ouput buffer just add this as the top line of your script:
PHP Code:
<?php
ob_start();
?>
You can do some pretty neat things with output buffers, such as nesting and compression so it is also worth looking at the other functions which relate to ouput buffering.
http://uk.php.net/manual/en/ref.outcontrol.php
-
Feb 15th, 2005, 03:45 AM
#4
Re: Header crap. Give me response.redirect anyday.. Can you turn me back?
There WAS output before the redirect: the notice that was generated by accessing a non-existent array element.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 15th, 2005, 09:39 AM
#5
Re: Header crap. Give me response.redirect anyday.. Can you turn me back?
 Originally Posted by CornedBee
There WAS output before the redirect: the notice that was generated by accessing a non-existent array element.
Isn't that what I said?
Tg
-
Feb 15th, 2005, 09:47 AM
#6
Re: Header. Give me response.redirect anyday.. Can you turn me back?
Yes, but the problem is so common that your mention was not prominent enough.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|