473,320 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

Jul 17 '05 #1
19 2942
so***@mic.gov.eg wrote:
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


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, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2
>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


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

Jul 17 '05 #3
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

Jul 17 '05 #4


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

Jul 17 '05 #5
so***@mic.gov.eg wrote:
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


Give us the first lines of your code up to the row where you use
header().

Regards,
Matthias
Jul 17 '05 #6
If you are having allot of trouble with this, try buffering the output
by using:
"ob_start()" and "ob_flush()"...
See ref: http://us2.php.net/manual/en/function.ob-start.php

Jul 17 '05 #7
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();
?>

Jul 17 '05 #8
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
<so***@mic.gov.eg> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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

Jul 17 '05 #9
Ged Robinson wrote upside-down:
print("<meta http-equiv=\"refresh\" content=\"3;URL=$url\">");


Groups-beta (spit) will tell you why the META refresh hack
is usually inferior; it is no substitute for a proper
redirection.

--
Jock
Jul 17 '05 #10
.oO(Ged Robinson)
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\">");
The correct way for redirects is sending an appropriate status code back
the browser. Additionally the HTTP referrer is unreliable.
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 ???


You should read this:

Use standard redirects: don't break the back button!
http://www.w3.org/QA/Tips/reback

Micha
Jul 17 '05 #11
Thanks for that Micha.

Now I understand why it's not a good technique.

G

"Michael Fesser" <ne*****@gmx.net> wrote in message
news:gj********************************@4ax.com...
.oO(Ged Robinson)
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\">");
The correct way for redirects is sending an appropriate status code back
the browser. Additionally the HTTP referrer is unreliable.
I don't understand enough to know whether using this method can be dangerousor not recommended for some reason. Maybe not all browsers support it

???
You should read this:

Use standard redirects: don't break the back button!
http://www.w3.org/QA/Tips/reback

Micha

Jul 17 '05 #12
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.

Jul 17 '05 #13
please i need any help urgently.

Jul 17 '05 #14
In article <11*********************@f14g2000cwb.googlegroups. com>,
"Soha" <so***@mic.gov.eg> wrote:
please i need any help urgently.


http://us2.php.net/manual/en/function.header.php

--
DeeDee, don't press that button! DeeDee! NO! Dee...

Jul 17 '05 #15
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

Jul 17 '05 #16
.oO(Soha)
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


Upload a copy of the script with the extension .phps and post a link to
it.

Micha
Jul 17 '05 #17
In article <11**********************@z14g2000cwz.googlegroups .com>,
"Soha" <so***@mic.gov.eg> wrote:
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


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...

Jul 17 '05 #18
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.

Jul 17 '05 #19
.oO(Soha)
i haven't "echo'ed some sort of output" but i have used the fwrite()
function and this is the problem.
fwrite() shouldn't be the problem, it writes to local disk and doesn't
cause a server response.
i tried to use the ob_start() and
ob_end_flush() but still it didn't work.
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 ...')?
please need help as soon as
possible and for more information i have post my code in a previouse
message.


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
Jul 17 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul | last post by:
I'm not getting the results I want when I use Response.Redirct in a ASP page. I enter this line of code in a asp page from domain1.com. Response.Redirect...
2
by: T Conti | last post by:
Howdy: I have converted a huge ASP page over to .Net (C#). The old page has been will be removed from our site, but I need to have a dummy page there that will redirect the user to the new site...
8
by: Victor | last post by:
I need to redirect to another web page, but that redirect will include the submission of form data. So, unlike ServerXMLHTTP which stays on the originating web page, I need the script to redirect...
3
by: Pooja Renukdas | last post by:
Hello, I have this web site where only two pages have to be secure pages and I need to call them using https, but since I have my development server and my production web server, I dont want to...
8
by: Mantorok | last post by:
Hi all When I start a new thread that tries to call: HttpContext.Current.Response.Redirect() It fails as Current returns null, is there anyway to access the current httpcontext from within...
1
by: David | last post by:
I need to redirect to a page and HTTP Post data. The Response.Redirect does not work and the HTTPREQUEST option calls the page and waits for a response, but I need to transfer control to the...
6
by: Coleen | last post by:
Hi all :-) I need to redirect to multiple pages on click of a transmit button, without redisplaying each page. This redirection is to capture session variables that are created on each page and...
1
by: rouellette | last post by:
Is it possible to redirect to another page in your application from the start page BEFORE the user has been authenticated if you're using FORMS authentication? I can't seem to get it to work. ...
4
by: =?Utf-8?B?SlA=?= | last post by:
All the sudden my app has started to loose Session values after a Response.Redirect to another page in the same project. Ive read several post about setting the Terminate Boolean to false to solve...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.