
July 17th, 2005, 10:57 AM
| | | to redirect to another page
I want to redirect to another file, isn't this the right code to do so
header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/images/$file_name");
the interpreter give me this erorr instead of redirecting
Warning: Cannot modify header information - headers already sent by
(output started at E:\tryphp\direct.php:9) in E:\tryphp\direct.php on
line 70
what's wrong in the code coz i don't understand the erorr | 
July 17th, 2005, 10:57 AM
| | | Re: to redirect to another page soham@mic.gov.eg wrote:[color=blue]
> I want to redirect to another file, isn't this the right code to do so
>
> header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/images/$file_name");
>
> the interpreter give me this erorr instead of redirecting
>
> Warning: Cannot modify header information - headers already sent by
> (output started at E:\tryphp\direct.php:9) in E:\tryphp\direct.php on
> line 70
>
> what's wrong in the code coz i don't understand the erorr
>[/color]
Probably nothing wrong with the code. 'headers already sent' errors are
usually caused by whitespace that is already sent to the browser before
the header(), for example a space or return before the '<?php' start tag.
JP
--
Sorry, <devnull@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @. | 
July 17th, 2005, 10:57 AM
| | | Re: to redirect to another page
>I want to redirect to another file, isn't this the right code to do so[color=blue]
>
>header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/images/$file_name");
>
>the interpreter give me this erorr instead of redirecting
>
>Warning: Cannot modify header information - headers already sent by
>(output started at E:\tryphp\direct.php:9) in E:\tryphp\direct.php on
>line 70
>
>what's wrong in the code coz i don't understand the erorr[/color]
Send the headers BEFORE anything else. Don't send anything else
(like "<HTML>", or DOCTYPE, or even a blank line) before that.
Error or warning messages output to the page can also cause trouble.
What's on line 9 of direct.php?
Gordon L. Burditt | 
July 17th, 2005, 10:57 AM
| | | Re: to redirect to another page
on line 9 there was "<?php" and i removed all the "<HTML>", or DOCTYPE
echo() but now i got the same erorr msg but where i write in a file
"fwrite($fileh,$file_array[$i]);" and this part is very important and i
can't remove it. how to solve this problem | 
July 17th, 2005, 10:57 AM
| | | Re: to redirect to another page
please check any echo or print statement(function that send contents to
the broswer) in current file or include files.
if this do not resolve your problem use output buffer functions to
control output.
usefule output buffer functions : ob_start(), ob_end_flush().
see also: http://groups-beta.google.com/group/php_programming | 
July 17th, 2005, 10:57 AM
| | | Re: to redirect to another page soham@mic.gov.eg wrote:
[color=blue]
> on line 9 there was "<?php" and i removed all the "<HTML>", or DOCTYPE
> echo() but now i got the same erorr msg but where i write in a file
> "fwrite($fileh,$file_array[$i]);" and this part is very important and i
> can't remove it. how to solve this problem[/color]
Give us the first lines of your code up to the row where you use
header().
Regards,
Matthias | 
July 17th, 2005, 10:58 AM
| | | Re: to redirect to another page
This is my code:
<?php
$file_name=$_GET['filen'];
$vd_flag=$_GET['vd'];
$count_file=realpath("./count.txt");
$file_array=file($count_file);
$num=count($file_array);
$found=0;
for ($i=0;$i<$num;$i++){
if (strpos($file_array[$i], $file_name)===false)
//echo 'Not found';
else{
list($filen,$view,$down)=split("\t",$file_array[$i]);
$view=(int)$view;
$down=(int)$down;
if ($vd_flag==1){
$viewc=++$view;
$downc=$down;
}//if view is choosen
elseif ($vd_flag==2){
$viewc=$view;
$downc=++$down;
}//if download is choosen
$file_array[$i]=$file_name."\t".$viewc."\t".$downc."\n";
$found=1;
break;
}//end if file name found in the array
}//end for loop
if ($found==0){
if ($vd_flag==1){
$viewc=1;
$downc="0";
}//if view is choosen
elseif ($vd_flag==2){
$viewc="0";
$downc=1;
}//if download is choosen
$file_array[$num]=$file_name."\t".$viewc."\t".$downc."\n";
}//file name not found
$numi=++$num;
if ($fileh=fopen($count_file,"w")){
if (flock($fileh,2)){
for ($i=0;$i<$numi;$i++){
fwrite($fileh,$file_array[$i]);
}//end for loop
}
else{
header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/direct.php?filen=$file_name&vd=$vd_flag");
exit();
}
}// write the array to the file
fclose($fileh);
header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/images/$file_name");
exit();
?> | 
July 17th, 2005, 10:58 AM
| | | Re: to redirect to another page
I had trouble with this error, then I saw someone recommend using another
way to perform the redirection, for example, like this....
$url=$HTTP_REFERER;
print("<meta http-equiv=\"refresh\" content=\"3;URL=$url\">");
Your url would be
"http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/images/$file
_name" of course.
If you replace the 3 with a 0 the redirection occurs straight away.
I don't understand enough to know whether using this method can be dangerous
or not recommended for some reason. Maybe not all browsers support it ???
This is what I use anyway. It avoids the "headers already sent" error
you're seeing.
Anyone got any comments on it ??
Ged
<soham@mic.gov.eg> wrote in message
news:1102682022.674813.185140@z14g2000cwz.googlegr oups.com...[color=blue]
> I want to redirect to another file, isn't this the right code to do so
>
>[/color]
header("Location:http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']
)."/images/$file_name");[color=blue]
>
> the interpreter give me this erorr instead of redirecting
>
> Warning: Cannot modify header information - headers already sent by
> (output started at E:\tryphp\direct.php:9) in E:\tryphp\direct.php on
> line 70
>
> what's wrong in the code coz i don't understand the erorr
>[/color] | 
July 17th, 2005, 10:58 AM
| | | Re: to redirect to another page
Ged Robinson wrote upside-down:
[color=blue]
> print("<meta http-equiv=\"refresh\" content=\"3;URL=$url\">");[/color]
Groups-beta (spit) will tell you why the META refresh hack
is usually inferior; it is no substitute for a proper
redirection.
--
Jock | 
July 17th, 2005, 10:58 AM
| | | Re: to redirect to another page
.oO(Ged Robinson)
[color=blue]
>I had trouble with this error, then I saw someone recommend using another
>way to perform the redirection, for example, like this....
>
>$url=$HTTP_REFERER;
>print("<meta http-equiv=\"refresh\" content=\"3;URL=$url\">");[/color]
The correct way for redirects is sending an appropriate status code back
the browser. Additionally the HTTP referrer is unreliable.
[color=blue]
>I don't understand enough to know whether using this method can be dangerous
>or not recommended for some reason. Maybe not all browsers support it ???[/color]
You should read this:
Use standard redirects: don't break the back button! http://www.w3.org/QA/Tips/reback
Micha | 
July 17th, 2005, 10:58 AM
| | | Re: to redirect to another page
Thanks for that Micha.
Now I understand why it's not a good technique.
G
"Michael Fesser" <netizen@gmx.net> wrote in message
news:gjtmr09inerc4md0pkkgpicfpap8u8nmml@4ax.com...[color=blue]
> .oO(Ged Robinson)
>[color=green]
> >I had trouble with this error, then I saw someone recommend using another
> >way to perform the redirection, for example, like this....
> >
> >$url=$HTTP_REFERER;
> >print("<meta http-equiv=\"refresh\" content=\"3;URL=$url\">");[/color]
>
> The correct way for redirects is sending an appropriate status code back
> the browser. Additionally the HTTP referrer is unreliable.
>[color=green]
> >I don't understand enough to know whether using this method can be[/color][/color]
dangerous[color=blue][color=green]
> >or not recommended for some reason. Maybe not all browsers support it[/color][/color]
???[color=blue]
>
> You should read this:
>
> Use standard redirects: don't break the back button!
> http://www.w3.org/QA/Tips/reback
>
> Micha[/color] | 
July 17th, 2005, 10:58 AM
| | | Re: to redirect to another page
i didn't want to use the meta method but could any one tell me how to
do a redirect. now my problem lies in the fwrite() function when i run
the script it give me a warning on that part where i try to write in a
file. i tried to use ob_start() and ob_end_flush() but it didn't work.
please i need any help urgently. | 
July 17th, 2005, 10:59 AM
| | | Re: to redirect to another page
please i need any help urgently. | 
July 17th, 2005, 10:59 AM
| | | Re: to redirect to another page
In article <1102934873.648283.16080@f14g2000cwb.googlegroups. com>,
"Soha" <soham@mic.gov.eg> wrote:
[color=blue]
> please i need any help urgently.[/color] http://us2.php.net/manual/en/function.header.php
--
DeeDee, don't press that button! DeeDee! NO! Dee... | 
July 17th, 2005, 11:00 AM
| | | Re: to redirect to another page
i'm already using the header() function but i have a problem when i try
to write in the file before using the header() function. i tried to use
ob_start() and ob_end_flush() but still the script return the same
error
Warning: Cannot modify header information - headers already sent
by(output started at E:\tryphp\direct.php:9) in E:\tryphp\direct.php on
line 70 | 
July 17th, 2005, 11:00 AM
| | | Re: to redirect to another page
.oO(Soha)
[color=blue]
>i'm already using the header() function but i have a problem when i try
>to write in the file before using the header() function. i tried to use
>ob_start() and ob_end_flush() but still the script return the same
>error
>Warning: Cannot modify header information - headers already sent
>by(output started at E:\tryphp\direct.php:9) in E:\tryphp\direct.php on
>line 70[/color]
Upload a copy of the script with the extension .phps and post a link to
it.
Micha | 
July 17th, 2005, 11:00 AM
| | | Re: to redirect to another page
In article <1102950738.939643.259400@z14g2000cwz.googlegroups .com>,
"Soha" <soham@mic.gov.eg> wrote:
[color=blue]
> i'm already using the header() function but i have a problem when i try
> to write in the file before using the header() function. i tried to use
> ob_start() and ob_end_flush() but still the script return the same
> error
> Warning: Cannot modify header information - headers already sent
> by(output started at E:\tryphp\direct.php:9) in E:\tryphp\direct.php on
> line 70[/color]
I'll bet somewhere in your script _before_ you call the header()
function, you've echo'ed some sort of output. That sends a header.
Make sure header() is the first thing you call.
--
DeeDee, don't press that button! DeeDee! NO! Dee... | 
July 17th, 2005, 11:01 AM
| | | Re: to redirect to another page
i haven't "echo'ed some sort of output" but i have used the fwrite()
function and this is the problem. i tried to use the ob_start() and
ob_end_flush() but still it didn't work. please need help as soon as
possible and for more information i have post my code in a previouse
message. | 
July 17th, 2005, 11:01 AM
| | | Re: to redirect to another page
.oO(Soha)
[color=blue]
>i haven't "echo'ed some sort of output" but i have used the fwrite()
>function and this is the problem.[/color]
fwrite() shouldn't be the problem, it writes to local disk and doesn't
cause a server response.
[color=blue]
>i tried to use the ob_start() and
>ob_end_flush() but still it didn't work.[/color]
Where did you add ob_start()? It should be one of the first things in a
script. What is on the line the interpreter complains about ('output
startet at ...')?
[color=blue]
>please need help as soon as
>possible and for more information i have post my code in a previouse
>message.[/color]
Posted code doesn't show if there's something (blanks, new lines) before
an opening <?php in your file, which could cause the server to send its
headers.
Micha |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|