9 Replies Latest reply on Nov 2, 2008 5:26 PM by Newsgroup_User

    PHP Redirect syntax error

    Level 7
      > I have 2 files I would like to redirect to after running a script.
      > Call them 'thislist.php' and 'thatlist.php'.
      >
      > So, if $agency='this';
      >
      > what is the correct syntax to redirect to thislist.php?
      >
      > This gives me an unexpected T_STRING error:
      > header ("Location: ".$agency."list.php");
      >
      > I have tried several variations, but no luck.
      >
      > Thanks!
      > Harvey

      Actually, I may have a different problem. I get the unexpected T_STRING
      error with this as well:

      header ("Location: thislist.php");

      What am I doing wrong?

      Thanks,
      Harvey
        • 1. Re: PHP Redirect syntax error
          Level 7
          if ($agency == 'this') {
          header("Location: ". $agency . "list.php");
          }

          But - why do the test if the location is going to be the concatenated value
          of the $agency string with 'list.php'?

          --
          Murray --- ICQ 71997575
          Adobe Community Expert
          (If you *MUST* email me, don't LAUGH when you do so!)
          ==================
          http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
          http://www.dwfaq.com - DW FAQs, Tutorials & Resources
          ==================


          "eclipsme" <none@nowhere.com> wrote in message
          news:gekvhn$g6c$1@forums.macromedia.com...
          > > I have 2 files I would like to redirect to after running a script.
          > > Call them 'thislist.php' and 'thatlist.php'.
          > >
          > > So, if $agency='this';
          > >
          > > what is the correct syntax to redirect to thislist.php?
          > >
          > > This gives me an unexpected T_STRING error:
          > > header ("Location: ".$agency."list.php");
          > >
          > > I have tried several variations, but no luck.
          > >
          > > Thanks!
          > > Harvey
          >
          > Actually, I may have a different problem. I get the unexpected T_STRING
          > error with this as well:
          >
          > header ("Location: thislist.php");
          >
          > What am I doing wrong?
          >
          > Thanks,
          > Harvey

          • 2. Re: PHP Redirect syntax error
            Level 7
            Murray *ACE* wrote:
            > if ($agency == 'this') {
            > header("Location: ". $agency . "list.php");
            > }
            >
            > But - why do the test if the location is going to be the concatenated
            > value of the $agency string with 'list.php'?
            >
            No, it is the concatenation that is giving me trouble. The string error
            was the result of a missing ';'. That is solved. Now everything is
            working except I am not redirected. I am left with a blank page, which
            is the script page with no output.

            I had tried the syntax you give above, but it was the ';' that was
            messing me up.

            Now, this is working, except I have to investigate changing cases. The
            variable is upper case, but in this instance, I need lower case.

            This has been an arduous learning process, but I am on the edge of victory!

            Thanks Murray.
            Harvey
            • 3. Re: PHP Redirect syntax error
              Level 7
              if ($agency == 'this') {
              header("Location: ". $agency . "list.php");
              exit();
              }


              --
              Murray --- ICQ 71997575
              Adobe Community Expert
              (If you *MUST* email me, don't LAUGH when you do so!)
              ==================
              http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
              http://www.dwfaq.com - DW FAQs, Tutorials & Resources
              ==================


              "eclipsme" <none@nowhere.com> wrote in message
              news:gel5v9$o1g$1@forums.macromedia.com...
              > Murray *ACE* wrote:
              >> if ($agency == 'this') {
              >> header("Location: ". $agency . "list.php");
              >> }
              >>
              >> But - why do the test if the location is going to be the concatenated
              >> value of the $agency string with 'list.php'?
              >>
              > No, it is the concatenation that is giving me trouble. The string error
              > was the result of a missing ';'. That is solved. Now everything is working
              > except I am not redirected. I am left with a blank page, which is the
              > script page with no output.
              >
              > I had tried the syntax you give above, but it was the ';' that was messing
              > me up.
              >
              > Now, this is working, except I have to investigate changing cases. The
              > variable is upper case, but in this instance, I need lower case.
              >
              > This has been an arduous learning process, but I am on the edge of
              > victory!
              >
              > Thanks Murray.
              > Harvey

              • 4. Re: PHP Redirect syntax error
                Level 7
                eclipsme posted in macromedia.dreamweaver:

                > Murray *ACE* wrote:
                >> if ($agency == 'this') {
                >> header("Location: ". $agency . "list.php");
                >> }
                >>
                >> But - why do the test if the location is going to be the
                >> concatenated value of the $agency string with 'list.php'?
                >>
                > No, it is the concatenation that is giving me trouble. The string
                > error was the result of a missing ';'. That is solved. Now
                > everything is working except I am not redirected. I am left with a
                > blank page, which is the script page with no output.

                I have a recollection of a rush job where I had a similar problem. I
                never got the chance to discover why, but I did find a work-around that
                worked. Save the concatenation in a variable, then use that variable in
                the header() function.

                $loc = $agency. 'list.php';
                header("Location: $loc");

                Note: You should use a full URL for header(). ISTR prepending
                $_SERVER['HTTP_HOST'] for portability.


                --
                Mark A. Boyd
                Keep-On-Learnin' :)
                • 5. Re: PHP Redirect syntax error
                  Level 7
                  Mark A. Boyd wrote:
                  > eclipsme posted in macromedia.dreamweaver:
                  >
                  >> Murray *ACE* wrote:
                  >>> if ($agency == 'this') {
                  >>> header("Location: ". $agency . "list.php");
                  >>> }
                  >>>
                  >>> But - why do the test if the location is going to be the
                  >>> concatenated value of the $agency string with 'list.php'?
                  >>>
                  >> No, it is the concatenation that is giving me trouble. The string
                  >> error was the result of a missing ';'. That is solved. Now
                  >> everything is working except I am not redirected. I am left with a
                  >> blank page, which is the script page with no output.
                  >
                  > I have a recollection of a rush job where I had a similar problem. I
                  > never got the chance to discover why, but I did find a work-around that
                  > worked. Save the concatenation in a variable, then use that variable in
                  > the header() function.
                  >
                  > $loc = $agency. 'list.php';
                  > header("Location: $loc");
                  >
                  > Note: You should use a full URL for header(). ISTR prepending
                  > $_SERVER['HTTP_HOST'] for portability.
                  >
                  >
                  Thanks. I will look into this.
                  This syntax worked perfectly for me:
                  header("Location: ". $agency . "list.php");

                  Harvey
                  • 6. Re: PHP Redirect syntax error
                    Level 7
                    eclipsme posted in macromedia.dreamweaver:

                    > Mark A. Boyd wrote:
                    >>
                    >> Note: You should use a full URL for header(). ISTR prepending
                    >> $_SERVER['HTTP_HOST'] for portability.
                    >>
                    > Thanks. I will look into this.
                    > This syntax worked perfectly for me:
                    > header("Location: ". $agency . "list.php");

                    Glad to hear it.


                    --
                    Mark "alt.php" Boyd
                    Keep-On-Learnin' :)
                    • 7. Re: PHP Redirect syntax error
                      Level 7
                      Mark is correct, however. You must use a fully qualified link for the
                      redirection to comply with the letter of the law.

                      --
                      Murray --- ICQ 71997575
                      Adobe Community Expert
                      (If you *MUST* email me, don't LAUGH when you do so!)
                      ==================
                      http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                      http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                      ==================


                      "Mark A. Boyd" <lingoboyd@mboydDotcom.invalid> wrote in message
                      news:Xns9B4A9DE0A1AB0mblistssanDotrrcom@216.104.212.96...
                      > eclipsme posted in macromedia.dreamweaver:
                      >
                      >> Mark A. Boyd wrote:
                      >>>
                      >>> Note: You should use a full URL for header(). ISTR prepending
                      >>> $_SERVER['HTTP_HOST'] for portability.
                      >>>
                      >> Thanks. I will look into this.
                      >> This syntax worked perfectly for me:
                      >> header("Location: ". $agency . "list.php");
                      >
                      > Glad to hear it.
                      >
                      >
                      > --
                      > Mark "alt.php" Boyd
                      > Keep-On-Learnin' :)

                      • 8. Re: PHP Redirect syntax error
                        Level 7
                        Murray *ACE* posted in macromedia.dreamweaver:

                        > Mark is correct, however. You must use a fully qualified link for
                        > the redirection to comply with the letter of the law.

                        Yep. I never ran into any consequences before learning about it, but
                        why take chances?

                        As a side note, Harvey, you might find that comp.lang.php is more
                        active than alt.php. And it's in one of the original "Big 8" Usenet
                        heirarchies.


                        --
                        Mark "Get Out of Jail, Free" Boyd
                        Keep-On-Learnin' :)
                        • 9. Re: PHP Redirect syntax error
                          Level 7
                          Mark A. Boyd wrote:
                          > Murray *ACE* posted in macromedia.dreamweaver:
                          >
                          >> Mark is correct, however. You must use a fully qualified link for
                          >> the redirection to comply with the letter of the law.
                          >
                          > Yep. I never ran into any consequences before learning about it, but
                          > why take chances?
                          >
                          > As a side note, Harvey, you might find that comp.lang.php is more
                          > active than alt.php. And it's in one of the original "Big 8" Usenet
                          > heirarchies.
                          >
                          >
                          Thank you Mark. I just subscribed. Years ago I swore I would not be a
                          programmer. Oh well. Here we go again!

                          Harvey