form action = <?=$_SERVER['PHP_SELF']?> - stopped working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tHatDudeUK

    form action = <?=$_SERVER['PHP_SELF']?> - stopped working

    My form action code to submit values to itself have stopped working using
    the code

    form action = <?=$_SERVER['PHP_SELF']?>

    This code used to work

    My web host recently told me they enabled phpsuexec option in apache which
    apparently needs me to CHMOD my PHP page to 750 and the directory to 755. (I
    don't know what this means but know how to CHMOD files). I have CHMODed the
    files this but my PHP page doesn't work with those settings, so I set them
    back.

    Thanks in advance for any help.

    Best regards,

    tHatDudeUK


  • Andy Hassall

    #2
    Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working

    On Thu, 13 Jan 2005 19:54:06 -0000, "tHatDudeUK "
    <thatdudeuk@gma il.com.removeth isbit> wrote:
    [color=blue]
    >My form action code to submit values to itself have stopped working using
    >the code
    >
    >form action = <?=$_SERVER['PHP_SELF']?>[/color]

    You've got some extra spaces and missing quotes there. A step in the right
    direction would be:

    <form action="<?php echo htmlspecialchar s($_SERVER['PHP_SELF']);?>">
    [color=blue]
    >This code used to work
    >
    >My web host recently told me they enabled phpsuexec option in apache which
    >apparently needs me to CHMOD my PHP page to 750 and the directory to 755. (I
    >don't know what this means but know how to CHMOD files). I have CHMODed the
    >files this but my PHP page doesn't work with those settings, so I set them
    >back.[/color]

    Define "doesn't work". What does it do? What do you get in the HTML output?
    How does it differ from before?

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • tHatDudeUK

      #3
      Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working


      "Andy Hassall" <andy@andyh.co. uk> wrote in message
      news:oandu0pgo6 qsnl9adoq9n8v2p a6bmhhnne@4ax.c om...[color=blue]
      > You've got some extra spaces and missing quotes there. A step in the right
      > direction would be:
      >
      > <form action="<?php echo htmlspecialchar s($_SERVER['PHP_SELF']);?>">[/color]

      I've cut and paste that and no joy :-(
      [color=blue]
      > Define "doesn't work". What does it do? What do you get in the HTML
      > output?
      > How does it differ from before?[/color]

      I'll put all the relevant code at the bottom of this page so you can examine
      it. It doesn't work as in the values don't appear to be submitted to itself
      as in it won't print the error message if a box isn't ticked, and it won't
      forward to the page if it is ticked. It did work before! I'm not really very
      conversant with PHP although I managed to put this together myself with a
      little forum help etc. All I really need is the two tick boxes, to give an
      error message if not ticked, and to take to the appropriate page if ticked.

      <?php
      $message1 = "";
      $message2 = "";
      if (isset($Submit) && $Submit == "I consent and wish to participate")
      {
      if ($_POST[withdraw]!= "Yes")
      {
      $message1 = "You must tick the box in order to continue";
      }
      if ($_POST[noanswer]!= "Yes")
      {
      $message2 = "You must tick the box in order to continue";
      }
      if ($message1 == "" && $message2 == "")
      {
      header("Locatio n: http://www.an1.co.uk/survey");
      }
      }
      ?>

      <form action="<?php echo htmlspecialchar s($_SERVER['PHP_SELF']);?>"
      method="post" name="form1" class="style4">
      <p align="left">
      <input name="withdraw" type="checkbox" id="withdraw6"
      value="Yes">
      I understand that I may withdraw
      from this investigation at any stage <br>
      <span class="style3">
      <?php
      if ($message1!= "")
      {
      print "$message1" ;
      }
      ?>
      </span> </p>
      <p align="left">
      <input name="noanswer" type="checkbox" id="noanswer6"
      value="Yes">
      I understand that I am free to choose not to
      answer a question without giving a reason why
      <br>
      <span class="style3">
      <?php
      if ($message2!= "")
      {
      print "$message2" ;
      }
      ?>
      </span> </p>
      <p align="left">
      <input type="submit" name="Submit" value="I consent and wish
      to participate">
      </p>
      </form>


      Comment

      • Roy W. Andersen

        #4
        Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working

        tHatDudeUK wrote:[color=blue]
        > if (isset($Submit) && $Submit == "I consent and wish to participate")[/color]

        I'm guessing your ISP also turned register_global s off, meaning $Submit
        needs to be replaced with $_POST['Submit']. Basically, if
        register_global s is turned off, $Submit will never be set, and your
        statement will always evaluate to false.

        It's also a good idea to surround associative array keys with single
        quotes if they're literals (i.e. if they're not numbers or variables).

        $myvar['key'] is good, $myvar[key] isn't.
        $myvar[$key] is good, $myvar['$key'] isn't.

        I doubt that's causing your problem here though, but making a habit of
        doing it like that will decrease the chance of you running into trouble
        at some point due to conflict between an array key and a constant. I
        learned this the hard way ;)


        Roy W. Andersen
        --
        ra at broadpark dot no / http://roy.netgoth.org/

        "Hey! What kind of party is this? There's no booze
        and only one hooker!" - Bender, Futurama

        Comment

        • tHatDudeUK

          #5
          Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working


          "Roy W. Andersen" <roy-news@netgoth.or g> wrote in message
          news:34o6djF4du r9fU1@individua l.net...[color=blue]
          > tHatDudeUK wrote:[color=green]
          >> if (isset($Submit) && $Submit == "I consent and wish to participate")[/color]
          >
          > I'm guessing your ISP also turned register_global s off, meaning $Submit
          > needs to be replaced with $_POST['Submit']. Basically, if register_global s
          > is turned off, $Submit will never be set, and your statement will always
          > evaluate to false.[/color]

          Ok many thanks, looks like I have that bit sorted. Now I have a different
          problem.I get the following error message when it should send me to the page
          I want it to go to.

          Warning: Cannot modify header information - headers already sent by (output
          started at /home/an1cou/public_html/musicdownloadin g/index.php:2) in
          /home/an1cou/public_html/musicdownloadin g/index.php on line 17

          line 17 of the code is this one


          Comment

          • tHatDudeUK

            #6
            Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working


            "Roy W. Andersen" <roy-news@netgoth.or g> wrote in message
            news:34o6djF4du r9fU1@individua l.net...[color=blue]
            > tHatDudeUK wrote:[color=green]
            >> if (isset($Submit) && $Submit == "I consent and wish to participate")[/color]
            >
            > I'm guessing your ISP also turned register_global s off, meaning $Submit
            > needs to be replaced with $_POST['Submit']. Basically, if register_global s
            > is turned off, $Submit will never be set, and your statement will always
            > evaluate to false.[/color]

            Ok many thanks, looks like I have that bit sorted. Now I have a different
            problem.I get the following error message when it should send me to the page
            I want it to go to.

            Warning: Cannot modify header information - headers already sent by (output
            started at /home/an1cou/public_html/musicdownloadin g/index.php:2) in
            /home/an1cou/public_html/musicdownloadin g/index.php on line 17

            line 17 of the code is this one

            header("Locatio n: http://www.an1.co.uk/survey");


            Comment

            • Andy Hassall

              #7
              Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working

              On Thu, 13 Jan 2005 21:22:29 -0000, "tHatDudeUK "
              <thatdudeuk@gma il.com.removeth isbit> wrote:
              [color=blue]
              >
              >"Roy W. Andersen" <roy-news@netgoth.or g> wrote in message
              >news:34o6djF4d ur9fU1@individu al.net...[color=green]
              >> tHatDudeUK wrote:[color=darkred]
              >>> if (isset($Submit) && $Submit == "I consent and wish to participate")[/color]
              >>
              >> I'm guessing your ISP also turned register_global s off, meaning $Submit
              >> needs to be replaced with $_POST['Submit']. Basically, if register_global s
              >> is turned off, $Submit will never be set, and your statement will always
              >> evaluate to false.[/color]
              >
              >Ok many thanks, looks like I have that bit sorted. Now I have a different
              >problem.I get the following error message when it should send me to the page
              >I want it to go to.
              >
              >Warning: Cannot modify header information - headers already sent by (output
              >started at /home/an1cou/public_html/musicdownloadin g/index.php:2) in[/color]

              OK, so what's line 2?
              [color=blue]
              >/home/an1cou/public_html/musicdownloadin g/index.php on line 17
              >
              >line 17 of the code is this one
              >
              >header("Locati on: http://www.an1.co.uk/survey");[/color]

              See http://php.net/header

              --
              Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
              <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

              Comment

              • Michael Fesser

                #8
                Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working

                .oO(Roy W. Andersen)
                [color=blue]
                >It's also a good idea to surround associative array keys with single
                >quotes if they're literals (i.e. if they're not numbers or variables).[/color]

                It's an even better idea to set error_reporting to E_ALL in the php.ini,
                then PHP will complain about such things.

                Micha

                Comment

                • Roy W. Andersen

                  #9
                  Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working

                  tHatDudeUK wrote:[color=blue]
                  > Warning: Cannot modify header information - headers already sent by (output
                  > started at /home/an1cou/public_html/musicdownloadin g/index.php:2) in
                  > /home/an1cou/public_html/musicdownloadin g/index.php on line 17
                  >
                  > line 17 of the code is this one
                  >
                  > header("Locatio n: http://www.an1.co.uk/survey");[/color]

                  In the script you posted, that line is #16 if you count the line with
                  <?php as #1, which probably means you have a linebreak before your <?php
                  tag (or you didn't post the beginning of the script previously).

                  Headers must be sent before any actual content of the page. If you start
                  your page with a linebreak (or anything else) then that becomes a part
                  of the page, and hence once it's been sent to output you can't send any
                  more headers.

                  So, as your error explains, the actual page output started at line #2 of
                  index.php, which means you can't send a header on line #17. If you want
                  to redirect to a different page after you've started the output you'll
                  have to use a meta-tag or clientside script.


                  Roy W. Andersen
                  --
                  ra at broadpark dot no / http://roy.netgoth.org/

                  "Hey! What kind of party is this? There's no booze
                  and only one hooker!" - Bender, Futurama

                  Comment

                  • tHatDudeUK

                    #10
                    Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working


                    "Roy W. Andersen" <roy-news@netgoth.or g> wrote in message
                    news:34ob00F4ad p3nU1@individua l.net...[color=blue]
                    > In the script you posted, that line is #16 if you count the line with
                    > <?php as #1, which probably means you have a linebreak before your <?php
                    > tag (or you didn't post the beginning of the script previously).[/color]

                    Doh, silly me. All working now. Many thanks everyone...


                    Comment

                    • Michael Fesser

                      #11
                      Re: form action = &lt;?=$_SERV ER['PHP_SELF']?&gt; - stopped working

                      .oO(Roy W. Andersen)
                      [color=blue]
                      >So, as your error explains, the actual page output started at line #2 of
                      >index.php, which means you can't send a header on line #17. If you want
                      >to redirect to a different page after you've started the output you'll
                      >have to use a meta-tag or clientside script.[/color]

                      Never use unreliable client-side redirections if you're able to do it
                      properly with a server-side script. If necessary use output control
                      functions.

                      Micha

                      Comment

                      Working...