Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Header Help

    Hiya, just need help with PHP headers.

    Right, I have an index php page which has the following code within a header
    redirect:

    <?php
    if ( empty($_GET['month']) )
    if (empty($_GET['year']) )
    {
    $month = date(n);
    $year = date(Y);
    header("Location: index.php?month=$month&year=$year");
    }
    ?>

    On the same index.php page, I have a shoutbox (include file) which inputs
    the content of the shoutbox form into a database. After the user fills out
    the form, I want the index page to refresh again because if I leave it as it
    is and a user inputs info into the form, if they press refresh, the form
    resubmits thus recording two entries into the shoutbox, or however many
    times refresh is pressed.

    When I add a header redirect into the shoutbox include file, once the user
    clicks on send, index.php throws a headers cannot be sent error message.

    Can anyone help?

    Cheers.


    DaRemedy Guest

  2. Similar Questions and Discussions

    1. Image in header column (not replacing column header text)
      I have a sortable (asc/desc) datagrid and would like to add a small arrow icon (down/up) next to the column header text to improve the UI. Is this...
    2. php header() help
      I use the following code to redirect the browser on an error, header("location:error.php"); exit; Is it possible to pass POST variables on as if...
    3. Using header()?
      I have a Main.php file the gets data from the user. Main.php then loads Verify.php. Based on the input, Verify.php will load a page. An extract of...
    4. header
      Hi, a quick question. is it possible to send the header to the client only at the end of the page? I mean when the build of the page by the PHP...
    5. [PHP] Header()
      --- MiXmAsTr <mixmaster_@hotmail.com> wrote: header() allows you to set HTTP headers in your response to the client. What are you wanting to do...
  3. #2

    Default Re: Header help

    DaRemedy wrote:
    > Hiya, just need help with PHP headers.
    >
    Multi-posting to at least three different news groups, it looks like you
    need some help posting to usenet properly to...

    If you want to post to more than 1 newsgroup, use the Newsgroups: field to
    compose a comma-seperated list of target news groups. This procedure is
    called "Cross-posting" and prevents individual threads on the same topic.
    See the headers of this reply.
    > When I add a header redirect into the shoutbox include file, once the
    > user clicks on send, index.php throws a headers cannot be sent error
    > message.
    >
    To quote the manual page at [url]http://www.php.net/header:[/url]

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


    JW



    Janwillem Borleffs Guest

  4. #3

    Default Re: Header help

    I do apologise for cross posting.

    "Janwillem Borleffs" <jw@jwscripts.com> wrote in message
    news:415729d9$0$61750$abc4f4c3@news.euronet.nl...
    > DaRemedy wrote:
    > > Hiya, just need help with PHP headers.
    > >
    >
    > Multi-posting to at least three different news groups, it looks like you
    > need some help posting to usenet properly to...
    >
    > If you want to post to more than 1 newsgroup, use the Newsgroups: field to
    > compose a comma-seperated list of target news groups. This procedure is
    > called "Cross-posting" and prevents individual threads on the same topic.
    > See the headers of this reply.
    >
    > > When I add a header redirect into the shoutbox include file, once the
    > > user clicks on send, index.php throws a headers cannot be sent error
    > > message.
    > >
    >
    > To quote the manual page at [url]http://www.php.net/header:[/url]
    >
    > "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."
    >
    >
    > JW
    >
    >
    >

    DaRemedy Guest

  5. #4

    Default Re: Header help

    Even if I add the headers before any html output and making sure that there
    is no whitespace, the header still doesn't work, is it because the header o
    the index.php page is already being called? how do I get around it?

    Many thanks.

    "DaRemedy" <demonnet@btinternet.com.nospam> wrote in message
    news:cj7e8l$49r$1@titan.btinternet.com...
    > I do apologise for cross posting.
    >
    > "Janwillem Borleffs" <jw@jwscripts.com> wrote in message
    > news:415729d9$0$61750$abc4f4c3@news.euronet.nl...
    > > DaRemedy wrote:
    > > > Hiya, just need help with PHP headers.
    > > >
    > >
    > > Multi-posting to at least three different news groups, it looks like you
    > > need some help posting to usenet properly to...
    > >
    > > If you want to post to more than 1 newsgroup, use the Newsgroups: field
    to
    > > compose a comma-seperated list of target news groups. This procedure is
    > > called "Cross-posting" and prevents individual threads on the same
    topic.
    > > See the headers of this reply.
    > >
    > > > When I add a header redirect into the shoutbox include file, once the
    > > > user clicks on send, index.php throws a headers cannot be sent error
    > > > message.
    > > >
    > >
    > > To quote the manual page at [url]http://www.php.net/header:[/url]
    > >
    > > "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."
    > >
    > >
    > > JW
    > >
    > >
    > >
    >
    >

    DaRemedy Guest

  6. #5

    Default Re: Header help

    DaRemedy wrote:
    > Even if I add the headers before any html output and making sure that there
    > is no whitespace, the header still doesn't work, is it because the header o
    > the index.php page is already being called? how do I get around it?
    You have to be sure there aren't any whitespaces or html output on files that
    are included too.

    If you have more tha one header in the same file and they try to do simlare
    things you will run into a conflict (think the first one is the one that will
    be executed).
    J.O. Aho Guest

  7. #6

    Default Re: Header help

    Cheers for that,

    I managed to get it sorted using an 'if statement'. I made is so that if the
    shoutbox form is sent then to go to back index.php otherwise go to
    index.php?month=$month&year=$year. Telling the form to go back to index.php
    would call the month and year variables anyway, using:
    <?php
    (if form is sent do this) {
    header("Location: index.php");
    } else {
    if ( empty($_GET['month']) )
    if (empty($_GET['year']) )
    {
    $month = date(n);
    $year = date(Y);
    header("Location: index.php?month=$month&year=$year");
    }
    ?>

    Cheers for the help guys, really do appreciate it.

    "J.O. Aho" <user@example.net> wrote in message
    news:2rpg9cF1d0h92U1@uni-berlin.de...
    > DaRemedy wrote:
    >> Even if I add the headers before any html output and making sure that
    >> there
    >> is no whitespace, the header still doesn't work, is it because the header
    >> o
    >> the index.php page is already being called? how do I get around it?
    >
    > You have to be sure there aren't any whitespaces or html output on files
    > that are included too.
    >
    > If you have more tha one header in the same file and they try to do
    > simlare things you will run into a conflict (think the first one is the
    > one that will be executed).

    Sippy Guest

  8. #7

    Default Re: Header help

    .oO(Sippy)

    One more thing:
    >header("Location: index.php?month=$month&year=$year");
    The Location-header requires an absolute address, including the scheme
    ([url]http://)[/url] and hostname.

    Micha
    Michael Fesser Guest

  9. #8

    Default Re: Header help

    Thanks Michael,

    Is it absolutely nessecary to use an absolute address? because the code i
    posted in an earlier post seems to work fine without any problems.

    What I would really need to do is to change the header redirect slightly to
    redirect to the same page that the shoutbox was filled in from, e.g. the
    shoutbox was filled in from, lets say, the about.php page, so I would want
    the shoutbox to go back to that particular page after the form is submitted.
    Would I need to use $_SERVER['PHP_SELF'];

    Cheers.

    Sippy.

    "Michael Fesser" <netizen@gmx.net> wrote in message
    news:fapgl0p1a6ss3i74prbfacvv9cak8i36cj@4ax.com...
    > .oO(Sippy)
    >
    > One more thing:
    >
    > >header("Location: index.php?month=$month&year=$year");
    >
    > The Location-header requires an absolute address, including the scheme
    > ([url]http://)[/url] and hostname.
    >
    > Micha

    DaRemedy Guest

  10. #9

    Default Re: Header help

    .oO(DaRemedy)
    >Is it absolutely nessecary to use an absolute address? because the code i
    >posted in an earlier post seems to work fine without any problems.
    It works in most browsers (doesn't necessarily mean it'll work in all),
    but a full address is required by the HTTP specification (RFC 2616):

    "The field value consists of a single absolute URI."

    In the PHP manual there's a little example on how to add scheme and
    hostname automatically to build an absolute address from a relative one
    for an RFC-compliant Location-header.

    [url]http://www.php.net/header[/url]
    >What I would really need to do is to change the header redirect slightly to
    >redirect to the same page that the shoutbox was filled in from, e.g. the
    >shoutbox was filled in from, lets say, the about.php page, so I would want
    >the shoutbox to go back to that particular page after the form is submitted.
    >Would I need to use $_SERVER['PHP_SELF'];
    Yep.

    Micha
    Michael Fesser Guest

  11. #10

    Default Re: Header help

    Cheers matey, I really do appreciate your help.

    "Michael Fesser" <netizen@gmx.net> wrote in message
    news:1ntgl0l368vrqt06t56r5qd5coneu8k0sm@4ax.com...
    > .oO(DaRemedy)
    >
    > >Is it absolutely nessecary to use an absolute address? because the code i
    > >posted in an earlier post seems to work fine without any problems.
    >
    > It works in most browsers (doesn't necessarily mean it'll work in all),
    > but a full address is required by the HTTP specification (RFC 2616):
    >
    > "The field value consists of a single absolute URI."
    >
    > In the PHP manual there's a little example on how to add scheme and
    > hostname automatically to build an absolute address from a relative one
    > for an RFC-compliant Location-header.
    >
    > [url]http://www.php.net/header[/url]
    >
    > >What I would really need to do is to change the header redirect slightly
    to
    > >redirect to the same page that the shoutbox was filled in from, e.g. the
    > >shoutbox was filled in from, lets say, the about.php page, so I would
    want
    > >the shoutbox to go back to that particular page after the form is
    submitted.
    > >Would I need to use $_SERVER['PHP_SELF'];
    >
    > Yep.
    >
    > Micha

    DaRemedy Guest

  12. #11

    Default help

    Ответьте, пожалуйста, если вам, это, не обидно, если не трудно!
    Мой сервер не поддерживает CGI, ASP, PHP, SSI , но я имею скрипт PHP, который необходим для работы страницы ....
    Куда ийти, что сделать, чтобы дать поддержку страницы на моём сервере? Что, ещё, рекомендуете? [email]perovss@rol.ru[/email]

    Answer, please, if to you, it, is not insulting, if not it is difficult!
    My server does not support CGI, ASP, PHP, SSI, but I have скрипт PHP, which is necessary for work of page....
    Where ийти what to make to give support of page on my server? What, still, recommend?
    [email]perovss@rol.ru[/email]
    Guest

  13. #12

    Default Re: help

    While the city slept, [email]petrovss@rol.ru[/email] (petrovss@rol.ru) feverishly typed...
    > Answer, please, if to you, it, is not insulting, if not it is
    > difficult!
    > My server does not support CGI, ASP, PHP, SSI, but I have скрипт PHP,
    > which is necessary for work of page....
    > Where ийти what to make to give support of page on my server? What,
    > still, recommend?
    If you need to use a php script for your site, but your server doesn't
    support PHP, you have 2 options.

    1. Persuade whoever hosts your site to install PHP for you.

    2. Move to a host that does support PHP. I personally reccomend Affordable
    Host ( [url]http://www.affordablehost.com[/url] ). You can get PHP enabled hosting
    there for as little as $35.95USD / Year if you don't need MySQL, or
    $5.95USD/month if you do need MySQL.

    Hope that helps,
    Nige

    --
    Nigel Moss
    [url]http://www.nigenet.org.uk[/url]
    Mail address not valid. [email]nigel@DOG.nigenet.org.uk[/email], take the DOG. out!
    In the land of the blind, the one-eyed man is very, very busy!


    nice.guy.nige Guest

  14. #13

    Default Re: help

    We host for $3.50 / month with PHP4, MySQL4, 50 MB space, unlimited emails. [url]www.dynawest.cz[/url]

    "nice.guy.nige" <nigel_moss@deadspam.com> pн№e v diskusnнm pшнspмvku news:2t57sgF1r7t17U1@uni-berlin.de...
    > While the city slept, [email]petrovss@rol.ru[/email] (petrovss@rol.ru) feverishly typed...
    > > Answer, please, if to you, it, is not insulting, if not it is
    > > difficult!
    > > My server does not support CGI, ASP, PHP, SSI, but I have скрипт PHP,
    > > which is necessary for work of page....
    > > Where ийти what to make to give support of page on my server? What,
    > > still, recommend?
    >
    > If you need to use a php script for your site, but your server doesn't
    > support PHP, you have 2 options.
    >
    > 1. Persuade whoever hosts your site to install PHP for you.
    >
    > 2. Move to a host that does support PHP. I personally reccomend Affordable
    > Host ( [url]http://www.affordablehost.com[/url] ). You can get PHP enabled hosting
    > there for as little as $35.95USD / Year if you don't need MySQL, or
    > $5.95USD/month if you do need MySQL.
    >
    > Hope that helps,
    > Nige
    >
    > --
    > Nigel Moss
    > [url]http://www.nigenet.org.uk[/url]
    > Mail address not valid. [email]nigel@DOG.nigenet.org.uk[/email], take the DOG. out!
    > In the land of the blind, the one-eyed man is very, very busy!
    >
    >

    Ondra Zizka Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139