Can Constants Be Used Inside Header()?

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

    Can Constants Be Used Inside Header()?

    i have something similar to this:

    <?php
    header("Locatio n: http://mysite.com/destination.php ");
    ?>

    i would like to replace "mysite.com/destination.php " with a constant.

    for example, with a constant DESTINATION defined as
    "mysite.com/destination.php ".

    can this be done?

    if so, how?

    tia...

  • Chris Hope

    #2
    Re: Can Constants Be Used Inside Header()?

    skeeterbug wrote:
    [color=blue]
    > i have something similar to this:
    >
    > <?php
    > header("Locatio n: http://mysite.com/destination.php ");
    > ?>
    >
    > i would like to replace "mysite.com/destination.php " with a constant.
    >
    > for example, with a constant DESTINATION defined as
    > "mysite.com/destination.php ".
    >
    > can this be done?
    >
    > if so, how?[/color]

    You mean like this?

    define('DESTINA TION', 'http://mysite.com/destination.php ');
    ....
    header('Locatio n: ' . DESTINATION);

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • skeeterbug

      #3
      Re: Can Constants Be Used Inside Header()?

      >>You mean like this?

      define('DESTINA TION', 'http://mysite.com/destination.php ');
      ....
      header('Locatio n: ' . DESTINATION);<<

      this doesn't work for me.

      this is copy and paste... (except for mysite.com).

      define("ENTER_C USTOMER_URL", "http://mysite.com/index.php");
      header('Locatio n: ' . ENTER_CUSTOMER_ URL);

      Comment

      • Chris Hope

        #4
        Re: Can Constants Be Used Inside Header()?

        skeeterbug wrote:
        [color=blue][color=green][color=darkred]
        >>>You mean like this?[/color][/color]
        >
        > define('DESTINA TION', 'http://mysite.com/destination.php ');
        > ...
        > header('Locatio n: ' . DESTINATION);<<
        >
        > this doesn't work for me.
        >
        > this is copy and paste... (except for mysite.com).
        >
        > define("ENTER_C USTOMER_URL", "http://mysite.com/index.php");
        > header('Locatio n: ' . ENTER_CUSTOMER_ URL);[/color]

        So what actually happens when you try it?

        To debug, try doing this instead:

        define("ENTER_C USTOMER_URL", "http://mysite.com/index.php");
        print('Location : ' . ENTER_CUSTOMER_ URL);

        This way you get to see the output.

        --
        Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

        Comment

        • Michael Fesser

          #5
          Re: Can Constants Be Used Inside Header()?

          .oO(skeeterbug)
          [color=blue][color=green][color=darkred]
          >>>You mean like this?[/color][/color]
          >
          >define('DESTIN ATION', 'http://mysite.com/destination.php ');
          >...
          >header('Locati on: ' . DESTINATION);<<
          >
          >this doesn't work for me.[/color]

          How does it "not work"? Any error messages?
          [color=blue]
          >this is copy and paste... (except for mysite.com).
          >
          >define("ENTER_ CUSTOMER_URL", "http://mysite.com/index.php");
          >header('Locati on: ' . ENTER_CUSTOMER_ URL);[/color]

          Looks OK and works here (but please use www.example.com/org for example
          URLs, these domains are reserved for that purpose).

          Micha

          Comment

          • phpfunk@yahoo.com

            #6
            Re: Can Constants Be Used Inside Header()?

            Do you have exit(); after the header call? If not and you are running
            any code after the call, this could cause unwanted results.

            Comment

            • Alvaro G. Vicario

              #7
              Re: Can Constants Be Used Inside Header()?

              *** skeeterbug escribió/wrote (14 Jan 2005 15:24:39 -0800):[color=blue]
              > define("ENTER_C USTOMER_URL", "http://mysite.com/index.php");
              > header('Locatio n: ' . ENTER_CUSTOMER_ URL);[/color]

              Constants aren't any sort of mystery. Try:

              echo 'Location: ' . ENTER_CUSTOMER_ URL;

              and you'll see the exact argument you are passing to header(). BTW, perhaps
              you are missing an exit() somewhere after the redirection.


              --
              -+ Álvaro G. Vicario - Burgos, Spain
              +- http://www.demogracia.com (la web de humor barnizada para la intemperie)
              ++ Las dudas informáticas recibidas por correo irán directas a la papelera
              -+ I'm not a free help desk, please don't e-mail me your questions
              --

              Comment

              • skeeterbug

                #8
                Re: Can Constants Be Used Inside Header()?


                Chris Hope wrote:[color=blue]
                > skeeterbug wrote:
                >[color=green][color=darkred]
                > >>>You mean like this?[/color]
                > >
                > > define('DESTINA TION', 'http://mysite.com/destination.php ');
                > > ...
                > > header('Locatio n: ' . DESTINATION);<<
                > >
                > > this doesn't work for me.
                > >
                > > this is copy and paste... (except for mysite.com).
                > >
                > > define("ENTER_C USTOMER_URL", "http://mysite.com/index.php");
                > > header('Locatio n: ' . ENTER_CUSTOMER_ URL);[/color]
                >
                > So what actually happens when you try it?
                >
                > To debug, try doing this instead:
                >
                > define("ENTER_C USTOMER_URL", "http://mysite.com/index.php");
                > print('Location : ' . ENTER_CUSTOMER_ URL);
                >
                > This way you get to see the output.
                >
                > --
                > Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/[/color]


                chris, thanks for the tip. the value printed is the ocrrect url.

                i think the problem is how header handles variables within the quotes
                used to pass the string to the header function.

                there must be some kind of methodology for handling this - i'll search
                the net some and get back.

                Comment

                Working...