redirecting

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

    redirecting

    what is wrong with
    <?php
    if(!stristr($_S ERVER['SERVER_NAME'], 'www')) {
    Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
    exit();
    }
    ?>

    I am trying to make it redirect to www.theSpear.net if www. is not there,
    but it doesnt work.. any ideas?


  • E-Star

    #2
    Re: redirecting

    In article <xwEZa.118337$Y N5.84458@sccrns c01>, spearman <net@news.com >
    wrote:
    [color=blue]
    > I am trying to make it redirect to www.theSpear.net if www. is not there,
    > but it doesnt work.. any ideas?[/color]

    Perhaps you can check with your DNS host and configure a www subdomain.

    Comment

    • spearman

      #3
      Re: redirecting

      no.. i just ppl that go to theSpear.net to go to www.theSpear.net instead..
      dont want anything to happen between them.. just change it..
      "E-Star" <unix_core@linu xmail.org> wrote in message
      news:1008200322 08028085%unix_c ore@linuxmail.o rg...[color=blue]
      > In article <xwEZa.118337$Y N5.84458@sccrns c01>, spearman <net@news.com >
      > wrote:
      >[color=green]
      > > I am trying to make it redirect to www.theSpear.net if www. is not[/color][/color]
      there,[color=blue][color=green]
      > > but it doesnt work.. any ideas?[/color]
      >
      > Perhaps you can check with your DNS host and configure a www subdomain.[/color]


      Comment

      • DjDrakk

        #4
        Re: redirecting

        I don't see any problem with the code unless I'm missing something. Just
        make SURE that there is absolutely NO whitespace or any output to the
        browser before the headers are processed and sent. Meaning the following
        will NOT work:

        <html>
        <?php include 'includeme.php' ; ?>
        <?php
        if(!stristr($_S ERVER['SERVER_NAME'], 'www')) {
        Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
        exit();
        }
        ?>

        Double check the manual for more information on headers

        --

        Warren Butt
        -- Custom web design, cheap like cheese


        "spearman" <net@news.com > wrote in message
        news:xwEZa.1183 37$YN5.84458@sc crnsc01...[color=blue]
        > what is wrong with
        > <?php
        > if(!stristr($_S ERVER['SERVER_NAME'], 'www')) {
        > Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
        > exit();
        > }
        > ?>
        >
        > I am trying to make it redirect to www.theSpear.net if www. is not there,
        > but it doesnt work.. any ideas?
        >
        >[/color]


        Comment

        • blah

          #5
          Re: redirecting

          Because $_SERVER['SERVER_NAME'] will return the name of the server as
          SET on the server. So will probably always be 'www.thespear.n et' or
          whatever.


          You'd want: $_SERVER['HTTP_HOST'], although not all browsers send this.

          <?php
          if (!stristr($_SER VER['HTTP_HOST'], 'www') &&
          !empty($_SERVER['HTTP_HOST']))
          {
          Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
          exit();
          }
          ?>

          Would be a solution, with a check to avoid a race condition (browser
          that doesn't send a Host: header).


          spearman wrote:[color=blue]
          > what is wrong with
          > <?php
          > if(!stristr($_S ERVER['SERVER_NAME'], 'www')) {
          > Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
          > exit();
          > }
          > ?>
          >
          > I am trying to make it redirect to www.theSpear.net if www. is not there,
          > but it doesnt work.. any ideas?
          >
          >[/color]

          Comment

          • spearman

            #6
            Re: redirecting

            thanks alot! any easy way to also send all variables like (?id=1 stuff?)
            "blah" <bah@lah.com> wrote in message
            news:bh7can$kh2 $1@bunyip.cc.uq .edu.au...[color=blue]
            > Because $_SERVER['SERVER_NAME'] will return the name of the server as
            > SET on the server. So will probably always be 'www.thespear.n et' or
            > whatever.
            >
            >
            > You'd want: $_SERVER['HTTP_HOST'], although not all browsers send this.
            >
            > <?php
            > if (!stristr($_SER VER['HTTP_HOST'], 'www') &&
            > !empty($_SERVER['HTTP_HOST']))
            > {
            > Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
            > exit();
            > }
            > ?>
            >
            > Would be a solution, with a check to avoid a race condition (browser
            > that doesn't send a Host: header).
            >
            >
            > spearman wrote:[color=green]
            > > what is wrong with
            > > <?php
            > > if(!stristr($_S ERVER['SERVER_NAME'], 'www')) {
            > > Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
            > > exit();
            > > }
            > > ?>
            > >
            > > I am trying to make it redirect to www.theSpear.net if www. is not[/color][/color]
            there,[color=blue][color=green]
            > > but it doesnt work.. any ideas?
            > >
            > >[/color]
            >[/color]


            Comment

            • James

              #7
              Re: redirecting

              For "get queries"....

              You can try:

              header( "Location:
              http://www.theSpear.ne t$_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]" );

              On Mon, 11 Aug 2003 06:51:16 GMT, "spearman" <net@news.com > scrawled:
              [color=blue]
              >thanks alot! any easy way to also send all variables like (?id=1 stuff?)
              >"blah" <bah@lah.com> wrote in message
              >news:bh7can$kh 2$1@bunyip.cc.u q.edu.au...[color=green]
              >> Because $_SERVER['SERVER_NAME'] will return the name of the server as
              >> SET on the server. So will probably always be 'www.thespear.n et' or
              >> whatever.
              >>
              >>
              >> You'd want: $_SERVER['HTTP_HOST'], although not all browsers send this.
              >>
              >> <?php
              >> if (!stristr($_SER VER['HTTP_HOST'], 'www') &&
              >> !empty($_SERVER['HTTP_HOST']))
              >> {
              >> Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
              >> exit();
              >> }
              >> ?>
              >>
              >> Would be a solution, with a check to avoid a race condition (browser
              >> that doesn't send a Host: header).
              >>
              >>
              >> spearman wrote:[color=darkred]
              >> > what is wrong with
              >> > <?php
              >> > if(!stristr($_S ERVER['SERVER_NAME'], 'www')) {
              >> > Header("Locatio n: http://www.theSpear.ne t" . $_SERVER['PHP_SELF']);
              >> > exit();
              >> > }
              >> > ?>
              >> >
              >> > I am trying to make it redirect to www.theSpear.ne t if www. is not[/color][/color]
              >there,[color=green][color=darkred]
              >> > but it doesnt work.. any ideas?
              >> >
              >> >[/color]
              >>[/color]
              >
              >[/color]

              Comment

              • Ian.H [dS]

                #8
                Re: redirecting

                -----BEGIN PGP SIGNED MESSAGE-----
                Hash: SHA1

                Whilst lounging around on Mon, 11 Aug 2003 06:53:55 GMT,
                newsgroup@black-panther.freeser ve.co.uk (James) amazingly managed to
                produce the following with their Etch-A-Sketch:
                [color=blue]
                > For "get queries"....
                >
                > You can try:
                >
                > header( "Location:
                > http://www.theSpear.ne t$_SERVER[PHP_SELF]?$_SERVER[QUERY_STRING]"
                > );[/color]
                ^^ ^^ ^^ ^^

                Missing quotes!!!

                _ALWAYS_ quote these array elements! unless they're vars:


                $_SERVER['PHP_SELF']

                or

                $_GET[$foo]



                Regards,

                Ian

                -----BEGIN PGP SIGNATURE-----
                Version: PGP 8.0

                iQA/AwUBPzdGgWfqtj2 51CDhEQJe+gCgyR rS/EqNs7x/B1p3TvKzrnanED4 AnR1v
                DF/teF3j7tB0ZD8/2cL/VbfE
                =2FV1
                -----END PGP SIGNATURE-----

                --
                Ian.H [Design & Development]
                digiServ Network - Web solutions
                www.digiserv.ne t | irc.digiserv.ne t | forum.digiserv. net
                Programming, Web design, development & hosting.

                Comment

                Working...