redirecting to the same page with a different header... 
Author Message
 redirecting to the same page with a different header...

Hi all,

   I have written a database entry form, and my target is, after a
successfull entry, I want to redirect it to the same page with some GET
variables in the url to pass the previous variables to the same page for
reminding to user about what he has entered before.

Like this:(the file name called libadmin.php)

<?php
if ($HTTP_GET_VARS['start'])
{
    ...print variables from last post...

Quote:
}

elseif($HTTP_POST_VARS['record'])
{
   ....add to the vars in to the mysql tables...
   ... print "successfull" ...
   ... redirect to the same page with HTTP_GET_VARS, like this:
   header("Location:
http://www.*-*-*.com/ $prekod&p...");
exit();
Quote:
}

<form action=libadmin.php method=post>
.... form components ...
<submit>
</form>

but I am getting an error something like :

the record has been entered succesfully..
Warning: Cannot add header information - headers already sent by (output
started at /home/murtix/websites/new.murtix.com/library/libadmin.php:7) in /home/murtix/websites/new.murtix.com/library/libadmin.php on line 158

What would be the reason, how do I fix it?

Thanks

Murtix.



Sun, 29 May 2005 16:23:16 GMT  
 redirecting to the same page with a different header...

 1:<?php
 2:if ($HTTP_GET_VARS['start'])
 3:{
 4:   ...print variables from last post...
 5:}
 6:elseif($HTTP_POST_VARS['record'])
 7:{
 8:  ....add to the vars in to the mysql tables...
 9:  ... print "successfull" ...
10:  ... redirect to the same page with HTTP_GET_VARS, like this:
11:  header("Location:
12:http://www.website.com/library/libadmin.php?start=ST&prekod=$prekod&p...");
13:exit();
14:}
15:<form action=libadmin.php method=post>
16:.... form components ...
17:<submit>
18:</form>

Quote:
> but I am getting an error something like :

> the record has been entered succesfully..
> Warning: Cannot add header information - headers already sent by (output
> started at /home/murtix/websites/new.murtix.com/library/libadmin.php:7) in /home/murtix/websites/new.murtix.com/library/libadmin.php on line 158

> What would be the reason, how do I fix it?

Please carefully read the error:

header() (line 11 in the example above) can't be send because there was
already output (line 9 in the example) in the file ....libadmin.php
And like http://php.net/header says:
'Remember that header() must be called before any actual output is sent,
either by normal HTML tags, blank lines in a file, or from PHP. It is a
very common error to read code with include(), or require(), functions,
or another file access function, and have spaces or empty lines that are
output before header() is called. The same problem exists when using a
single PHP/HTML file.
<code>
Note: In PHP 4, you can use output buffering to get around this problem,
with the overhead of all of your output to the browser being buffered in
the server until you send it. You can do this by calling ob_start() and
ob_end_flush() in your script, or setting the output_buffering
configuration directive on in your php.ini or server configuration
files.'

But the easy workaround is not to do the print since it's of no use.
--

  Daniel Tryba



Sun, 29 May 2005 16:46:55 GMT  
 redirecting to the same page with a different header...
Now I got it, no output before the redirect... I got it. thanks...

:-)

Murtix.

Quote:


>  1:<?php
>  2:if ($HTTP_GET_VARS['start'])
>  3:{
>  4:   ...print variables from last post...
>  5:}
>  6:elseif($HTTP_POST_VARS['record'])
>  7:{
>  8:  ....add to the vars in to the mysql tables...
>  9:  ... print "successfull" ...
> 10:  ... redirect to the same page with HTTP_GET_VARS, like this:
> 11:  header("Location:
> 12:http://www.website.com/library/libadmin.php?start=ST&prekod=$prekod&p...");
> 13:exit();
> 14:}
> 15:<form action=libadmin.php method=post>
> 16:.... form components ...
> 17:<submit>
> 18:</form>

>> but I am getting an error something like :

>> the record has been entered succesfully..
>> Warning: Cannot add header information - headers already sent by (output
>> started at /home/murtix/websites/new.murtix.com/library/libadmin.php:7) in /home/murtix/websites/new.murtix.com/library/libadmin.php on line 158

>> What would be the reason, how do I fix it?

> Please carefully read the error:

> header() (line 11 in the example above) can't be send because there was
> already output (line 9 in the example) in the file ....libadmin.php
> And like http://php.net/header says:
> 'Remember that header() must be called before any actual output is sent,
> either by normal HTML tags, blank lines in a file, or from PHP. It is a
> very common error to read code with include(), or require(), functions,
> or another file access function, and have spaces or empty lines that are
> output before header() is called. The same problem exists when using a
> single PHP/HTML file.
> <code>
> Note: In PHP 4, you can use output buffering to get around this problem,
> with the overhead of all of your output to the browser being buffered in
> the server until you send it. You can do this by calling ob_start() and
> ob_end_flush() in your script, or setting the output_buffering
> configuration directive on in your php.ini or server configuration
> files.'

> But the easy workaround is not to do the print since it's of no use.



Sun, 29 May 2005 17:13:08 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Special Page header on first Page

2. Report with no page header on firs page

3. Report with no page header on firs page

4. Different pages for different users

5. Sessions and Redirect Headers

6. Header Error Using Redirect Scripts

7. Slow redirect with header() when form posted.

8. hiding url with header redirect

9. Header redirect

10. sessions and header redirect problems?

11. How to redirect stdin from a different window ?

12. A different header( ) problem

 

 
Powered by phpBB® Forum Software