Help: If isset query_string return 404

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

    #1

    Help: If isset query_string return 404

    I want my server to send a 404 header if a URL with a query string is
    requested. So if a browser or spider requests something
    like
    www. my_site .com?p=chair
    they would get a 404...

    But if they request
    www. my_site .com/chair.htm
    everything would be normal.

    With some assistance this is what I have so far, but it isn't working
    correctly. It always displays the 404, even when there is no question
    mark in the URL. Also, I would like the page to stop displaying anything
    after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
    it:


    if (isset($_SERVER["QUERY_STRI NG"])) {
    header("HTTP/1.0 404 Not Found");
    echo <<<HTML

    <head>
    <title>404 Not Found</title>
    </head>
    <body>
    <h1>Not Found</h1>
    The requested URL was not found on this server.
    </body>
    </html>

    HTML>>>;

    }

  • d

    #2
    Re: If isset query_string return 404

    "wd" <n23@nospam.inv alid> wrote in message
    news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=blue]
    >I want my server to send a 404 header if a URL with a query string is
    > requested. So if a browser or spider requests something
    > like
    > www. my_site .com?p=chair
    > they would get a 404...
    >
    > But if they request
    > www. my_site .com/chair.htm
    > everything would be normal.
    >
    > With some assistance this is what I have so far, but it isn't working
    > correctly. It always displays the 404, even when there is no question
    > mark in the URL. Also, I would like the page to stop displaying anything
    > after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
    > it:
    >
    >
    > if (isset($_SERVER["QUERY_STRI NG"])) {
    > header("HTTP/1.0 404 Not Found");
    > echo <<<HTML
    >
    > <head>
    > <title>404 Not Found</title>
    > </head>
    > <body>
    > <h1>Not Found</h1>
    > The requested URL was not found on this server.
    > </body>
    > </html>
    >
    > HTML>>>;
    >
    > }[/color]

    That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
    whether there's a query string or not. You might want to compare it to an
    empty string, or check its length. Checking whether it's set or not does
    not check the content at all...

    dave


    Comment

    • wd

      #3
      Re: If isset query_string return 404

      On Tue, 17 Jan 2006 12:06:45 +0000, d wrote:
      [color=blue]
      > "wd" <n23@nospam.inv alid> wrote in message
      > news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=green]
      >>I want my server to send a 404 header if a URL with a query string is
      >> requested. So if a browser or spider requests something
      >> like
      >> www. my_site .com?p=chair
      >> they would get a 404...
      >>
      >> But if they request
      >> www. my_site .com/chair.htm
      >> everything would be normal.
      >>
      >> With some assistance this is what I have so far, but it isn't working
      >> correctly. It always displays the 404, even when there is no question
      >> mark in the URL. Also, I would like the page to stop displaying anything
      >> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
      >> it:
      >>
      >>
      >> if (isset($_SERVER["QUERY_STRI NG"])) {
      >> header("HTTP/1.0 404 Not Found");
      >> echo <<<HTML
      >>
      >> <head>
      >> <title>404 Not Found</title>
      >> </head>
      >> <body>
      >> <h1>Not Found</h1>
      >> The requested URL was not found on this server.
      >> </body>
      >> </html>
      >>
      >> HTML>>>;
      >>
      >> }[/color]
      >
      > That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
      > whether there's a query string or not. You might want to compare it to an
      > empty string, or check its length. Checking whether it's set or not does
      > not check the content at all...
      >
      > dave[/color]

      So, the query_string just contains the URL that is requested? Could I
      just see if the query_string contains a question mark and then send the
      404 if a question mark is found?

      Comment

      • Kimmo Laine

        #4
        Re: If isset query_string return 404

        "wd" <n23@nospam.inv alid> wrote in message
        news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=blue]
        >I want my server to send a 404 header if a URL with a query string is
        > requested. So if a browser or spider requests something
        > like
        > www. my_site .com?p=chair
        > they would get a 404...
        >
        > But if they request
        > www. my_site .com/chair.htm
        > everything would be normal.
        >
        > With some assistance this is what I have so far, but it isn't working
        > correctly. It always displays the 404, even when there is no question
        > mark in the URL. Also, I would like the page to stop displaying anything
        > after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
        > it:
        >
        >
        > if (isset($_SERVER["QUERY_STRI NG"])) {[/color]


        Try something like if(sizeof($_GET )){...

        --
        "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
        spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)


        Comment

        • d

          #5
          Re: If isset query_string return 404

          "wd" <n23@nospam.inv alid> wrote in message
          news:pan.2006.0 1.17.12.17.01.4 95568@nospam.in valid...[color=blue]
          > On Tue, 17 Jan 2006 12:06:45 +0000, d wrote:
          >[color=green]
          >> "wd" <n23@nospam.inv alid> wrote in message
          >> news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=darkred]
          >>>I want my server to send a 404 header if a URL with a query string is
          >>> requested. So if a browser or spider requests something
          >>> like
          >>> www. my_site .com?p=chair
          >>> they would get a 404...
          >>>
          >>> But if they request
          >>> www. my_site .com/chair.htm
          >>> everything would be normal.
          >>>
          >>> With some assistance this is what I have so far, but it isn't working
          >>> correctly. It always displays the 404, even when there is no question
          >>> mark in the URL. Also, I would like the page to stop displaying
          >>> anything
          >>> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
          >>> do
          >>> it:
          >>>
          >>>
          >>> if (isset($_SERVER["QUERY_STRI NG"])) {
          >>> header("HTTP/1.0 404 Not Found");
          >>> echo <<<HTML
          >>>
          >>> <head>
          >>> <title>404 Not Found</title>
          >>> </head>
          >>> <body>
          >>> <h1>Not Found</h1>
          >>> The requested URL was not found on this server.
          >>> </body>
          >>> </html>
          >>>
          >>> HTML>>>;
          >>>
          >>> }[/color]
          >>
          >> That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
          >> whether there's a query string or not. You might want to compare it to
          >> an
          >> empty string, or check its length. Checking whether it's set or not does
          >> not check the content at all...
          >>
          >> dave[/color]
          >
          > So, the query_string just contains the URL that is requested? Could I
          > just see if the query_string contains a question mark and then send the
          > 404 if a question mark is found?[/color]

          No, $_SERVER["QUERY_STRI NG"] is empty when there is no query string. If
          there is a query string, say the page is:



          then $_SERVER["QUERY_STRI NG"]=="something" . Check to see if the string is
          empty, and if it is empty, then you're OK. If it's not empty, then a query
          string has been passed.

          dave


          Comment

          • d

            #6
            Re: If isset query_string return 404

            "Kimmo Laine" <spam@outolempi .net> wrote in message
            news:Dl5zf.3546 $sO4.1414@reade r1.news.jippii. net...[color=blue]
            > "wd" <n23@nospam.inv alid> wrote in message
            > news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=green]
            >>I want my server to send a 404 header if a URL with a query string is
            >> requested. So if a browser or spider requests something
            >> like
            >> www. my_site .com?p=chair
            >> they would get a 404...
            >>
            >> But if they request
            >> www. my_site .com/chair.htm
            >> everything would be normal.
            >>
            >> With some assistance this is what I have so far, but it isn't working
            >> correctly. It always displays the 404, even when there is no question
            >> mark in the URL. Also, I would like the page to stop displaying anything
            >> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
            >> it:
            >>
            >>
            >> if (isset($_SERVER["QUERY_STRI NG"])) {[/color]
            >
            >
            > Try something like if(sizeof($_GET )){...[/color]

            Just do this:

            if ($_SERVER["QUERY_STRI NG"]=="") {
            // OK
            } else {
            // Query string present
            }
            [color=blue]
            > --
            > "En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
            > spam@outolempi. net | Gedoon-S @ IRCnet | rot13(xvzzb@bhg byrzcv.arg)[/color]


            Comment

            • d

              #7
              Re: If isset query_string return 404

              "d" <d@example.co m> wrote in message
              news:yf6zf.2616 $wl.1038@text.n ews.blueyonder. co.uk...[color=blue]
              > "wd" <n23@nospam.inv alid> wrote in message
              > news:pan.2006.0 1.17.12.17.01.4 95568@nospam.in valid...[color=green]
              >> On Tue, 17 Jan 2006 12:06:45 +0000, d wrote:
              >>[color=darkred]
              >>> "wd" <n23@nospam.inv alid> wrote in message
              >>> news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...
              >>>>I want my server to send a 404 header if a URL with a query string is
              >>>> requested. So if a browser or spider requests something
              >>>> like
              >>>> www. my_site .com?p=chair
              >>>> they would get a 404...
              >>>>
              >>>> But if they request
              >>>> www. my_site .com/chair.htm
              >>>> everything would be normal.
              >>>>
              >>>> With some assistance this is what I have so far, but it isn't working
              >>>> correctly. It always displays the 404, even when there is no question
              >>>> mark in the URL. Also, I would like the page to stop displaying
              >>>> anything
              >>>> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
              >>>> do
              >>>> it:
              >>>>
              >>>>
              >>>> if (isset($_SERVER["QUERY_STRI NG"])) {
              >>>> header("HTTP/1.0 404 Not Found");
              >>>> echo <<<HTML
              >>>>
              >>>> <head>
              >>>> <title>404 Not Found</title>
              >>>> </head>
              >>>> <body>
              >>>> <h1>Not Found</h1>
              >>>> The requested URL was not found on this server.
              >>>> </body>
              >>>> </html>
              >>>>
              >>>> HTML>>>;
              >>>>
              >>>> }
              >>>
              >>> That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
              >>> whether there's a query string or not. You might want to compare it to
              >>> an
              >>> empty string, or check its length. Checking whether it's set or not
              >>> does
              >>> not check the content at all...
              >>>
              >>> dave[/color]
              >>
              >> So, the query_string just contains the URL that is requested? Could I
              >> just see if the query_string contains a question mark and then send the
              >> 404 if a question mark is found?[/color]
              >
              > No, $_SERVER["QUERY_STRI NG"] is empty when there is no query string. If
              > there is a query string, say the page is:
              >
              > http://somesite.com/?something
              >
              > then $_SERVER["QUERY_STRI NG"]=="something" . Check to see if the string is
              > empty, and if it is empty, then you're OK. If it's not empty, then a
              > query string has been passed.
              >
              > dave[/color]

              You can also use the empty() function, which upon reading has been quicker
              for some people than a straight comparison, not that comparisons are
              notoriously lenghthy in their execution, but even so... ;)


              Comment

              • Justin Koivisto

                #8
                Re: If isset query_string return 404

                d wrote:[color=blue]
                > "wd" <n23@nospam.inv alid> wrote in message
                > news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=green]
                >> I want my server to send a 404 header if a URL with a query string is
                >> requested. So if a browser or spider requests something
                >> like
                >> www. my_site .com?p=chair
                >> they would get a 404...
                >>
                >> But if they request
                >> www. my_site .com/chair.htm
                >> everything would be normal.
                >>
                >> With some assistance this is what I have so far, but it isn't working
                >> correctly. It always displays the 404, even when there is no question
                >> mark in the URL. Also, I would like the page to stop displaying anything
                >> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to do
                >> it:
                >>
                >> if (isset($_SERVER["QUERY_STRI NG"])) {
                >> header("HTTP/1.0 404 Not Found");[/color][/color]

                [snip]
                [color=blue]
                > That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
                > whether there's a query string or not.[/color]

                Not true. With apache, QUERY_STRING will always be set; however, with
                other web server software (ie. MS IIS) it will never be set unless you
                have done so yourself.

                Therefore, to be more portable, you may want to do something more like this:

                if(isset($_GET) && is_array($_GET) && count($_GET)){
                header("HTTP/1.0 404 Not Found");
                echo <<< HTML
                <html>
                <head>
                <title>404 Not Found</title>
                </head>
                <body>
                <h1>Not Found</h1>
                The requested URL was not found on this server.
                </body>
                </html>
                HTML;
                exit;
                }

                --
                Justin Koivisto, ZCE - justin@koivi.co m

                Comment

                • d

                  #9
                  Re: If isset query_string return 404

                  "Justin Koivisto" <justin@koivi.c om> wrote in message
                  news:8fGdnfvFR6 7enVDeRVn-ow@onvoy.com...[color=blue]
                  >d wrote:[color=green]
                  >> "wd" <n23@nospam.inv alid> wrote in message
                  >> news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=darkred]
                  >>> I want my server to send a 404 header if a URL with a query string is
                  >>> requested. So if a browser or spider requests something
                  >>> like
                  >>> www. my_site .com?p=chair
                  >>> they would get a 404...
                  >>>
                  >>> But if they request
                  >>> www. my_site .com/chair.htm
                  >>> everything would be normal.
                  >>>
                  >>> With some assistance this is what I have so far, but it isn't working
                  >>> correctly. It always displays the 404, even when there is no question
                  >>> mark in the URL. Also, I would like the page to stop displaying
                  >>> anything
                  >>> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
                  >>> do
                  >>> it:
                  >>>
                  >>> if (isset($_SERVER["QUERY_STRI NG"])) {
                  >>> header("HTTP/1.0 404 Not Found");[/color][/color]
                  >
                  > [snip]
                  >[color=green]
                  >> That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
                  >> whether there's a query string or not.[/color]
                  >
                  > Not true. With apache, QUERY_STRING will always be set; however, with
                  > other web server software (ie. MS IIS) it will never be set unless you
                  > have done so yourself.[/color]

                  Incorrect. I tested it with Apache and IIS. BOTH have
                  $_SERVER["QUERY_STRI NG"] set regardless of whether a query string is present
                  or not.
                  [color=blue]
                  > Therefore, to be more portable, you may want to do something more like
                  > this:
                  >
                  > if(isset($_GET) && is_array($_GET) && count($_GET)){
                  > header("HTTP/1.0 404 Not Found");
                  > echo <<< HTML
                  > <html>
                  > <head>
                  > <title>404 Not Found</title>
                  > </head>
                  > <body>
                  > <h1>Not Found</h1>
                  > The requested URL was not found on this server.
                  > </body>
                  > </html>
                  > HTML;
                  > exit;
                  > }[/color]

                  I don't want to sound rude, but that's ridiculous. Just check to see if
                  $_SERVER["QUERY_STRI NG"] is a non-empty string. If it is, then hey-presto,
                  you're set. You don't need to call isset, is_array and count all in one go.
                  [color=blue]
                  > --
                  > Justin Koivisto, ZCE - justin@koivi.co m
                  > http://koivi.com[/color]


                  Comment

                  • d

                    #10
                    Re: If isset query_string return 404

                    "Justin Koivisto" <justin@koivi.c om> wrote in message
                    news:8fGdnfvFR6 7enVDeRVn-ow@onvoy.com...[color=blue]
                    >d wrote:[color=green]
                    >> "wd" <n23@nospam.inv alid> wrote in message
                    >> news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=darkred]
                    >>> I want my server to send a 404 header if a URL with a query string is
                    >>> requested. So if a browser or spider requests something
                    >>> like
                    >>> www. my_site .com?p=chair
                    >>> they would get a 404...
                    >>>
                    >>> But if they request
                    >>> www. my_site .com/chair.htm
                    >>> everything would be normal.
                    >>>
                    >>> With some assistance this is what I have so far, but it isn't working
                    >>> correctly. It always displays the 404, even when there is no question
                    >>> mark in the URL. Also, I would like the page to stop displaying
                    >>> anything
                    >>> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
                    >>> do
                    >>> it:
                    >>>
                    >>> if (isset($_SERVER["QUERY_STRI NG"])) {
                    >>> header("HTTP/1.0 404 Not Found");[/color][/color]
                    >
                    > [snip]
                    >[color=green]
                    >> That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
                    >> whether there's a query string or not.[/color]
                    >
                    > Not true. With apache, QUERY_STRING will always be set; however, with
                    > other web server software (ie. MS IIS) it will never be set unless you
                    > have done so yourself.[/color]

                    I turned off a module in our engine, and you are correct - IIS won't set
                    QUERY_STRING unless prompted to. Regardless, it still doesn't merit calling
                    isset, is_array, and count just to check whether a string is empty or not.
                    [color=blue]
                    > Therefore, to be more portable, you may want to do something more like
                    > this:
                    >
                    > if(isset($_GET) && is_array($_GET) && count($_GET)){
                    > header("HTTP/1.0 404 Not Found");
                    > echo <<< HTML
                    > <html>
                    > <head>
                    > <title>404 Not Found</title>
                    > </head>
                    > <body>
                    > <h1>Not Found</h1>
                    > The requested URL was not found on this server.
                    > </body>
                    > </html>
                    > HTML;
                    > exit;
                    > }
                    >
                    > --
                    > Justin Koivisto, ZCE - justin@koivi.co m
                    > http://koivi.com[/color]


                    Comment

                    • d

                      #11
                      Re: If isset query_string return 404

                      "Justin Koivisto" <justin@koivi.c om> wrote in message
                      news:8fGdnfvFR6 7enVDeRVn-ow@onvoy.com...[color=blue]
                      >d wrote:[color=green]
                      >> "wd" <n23@nospam.inv alid> wrote in message
                      >> news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...[color=darkred]
                      >>> I want my server to send a 404 header if a URL with a query string is
                      >>> requested. So if a browser or spider requests something
                      >>> like
                      >>> www. my_site .com?p=chair
                      >>> they would get a 404...
                      >>>
                      >>> But if they request
                      >>> www. my_site .com/chair.htm
                      >>> everything would be normal.
                      >>>
                      >>> With some assistance this is what I have so far, but it isn't working
                      >>> correctly. It always displays the 404, even when there is no question
                      >>> mark in the URL. Also, I would like the page to stop displaying
                      >>> anything
                      >>> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
                      >>> do
                      >>> it:
                      >>>
                      >>> if (isset($_SERVER["QUERY_STRI NG"])) {
                      >>> header("HTTP/1.0 404 Not Found");[/color][/color]
                      >
                      > [snip]
                      >[color=green]
                      >> That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
                      >> whether there's a query string or not.[/color]
                      >
                      > Not true. With apache, QUERY_STRING will always be set; however, with
                      > other web server software (ie. MS IIS) it will never be set unless you
                      > have done so yourself.
                      >
                      > Therefore, to be more portable, you may want to do something more like
                      > this:[/color]

                      And not to mention your method only works if the query string is actually a
                      string of get parameters. If you pass just a string (as in his example),
                      the $_GET array is empty....
                      [color=blue]
                      > if(isset($_GET) && is_array($_GET) && count($_GET)){
                      > header("HTTP/1.0 404 Not Found");
                      > echo <<< HTML
                      > <html>
                      > <head>
                      > <title>404 Not Found</title>
                      > </head>
                      > <body>
                      > <h1>Not Found</h1>
                      > The requested URL was not found on this server.
                      > </body>
                      > </html>
                      > HTML;
                      > exit;
                      > }
                      >
                      > --
                      > Justin Koivisto, ZCE - justin@koivi.co m
                      > http://koivi.com[/color]


                      Comment

                      • Justin Koivisto

                        #12
                        Re: If isset query_string return 404

                        d wrote:[color=blue]
                        > "Justin Koivisto" <justin@koivi.c om> wrote in message
                        > news:8fGdnfvFR6 7enVDeRVn-ow@onvoy.com...[color=green]
                        >> d wrote:[color=darkred]
                        >>> "wd" <n23@nospam.inv alid> wrote in message
                        >>> news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...
                        >>>> I want my server to send a 404 header if a URL with a query string is
                        >>>> requested. So if a browser or spider requests something
                        >>>> like
                        >>>> www. my_site .com?p=chair
                        >>>> they would get a 404...
                        >>>>
                        >>>> But if they request
                        >>>> www. my_site .com/chair.htm
                        >>>> everything would be normal.
                        >>>>
                        >>>> With some assistance this is what I have so far, but it isn't working
                        >>>> correctly. It always displays the 404, even when there is no question
                        >>>> mark in the URL. Also, I would like the page to stop displaying
                        >>>> anything
                        >>>> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
                        >>>> do
                        >>>> it:
                        >>>>
                        >>>> if (isset($_SERVER["QUERY_STRI NG"])) {
                        >>>> header("HTTP/1.0 404 Not Found");[/color]
                        >> [snip]
                        >>[color=darkred]
                        >>> That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
                        >>> whether there's a query string or not.[/color]
                        >> Not true. With apache, QUERY_STRING will always be set; however, with
                        >> other web server software (ie. MS IIS) it will never be set unless you
                        >> have done so yourself.[/color]
                        >
                        > Incorrect. I tested it with Apache and IIS. BOTH have
                        > $_SERVER["QUERY_STRI NG"] set regardless of whether a query string is present
                        > or not.[/color]

                        Just because your IIS server has it does not mean that is the default.
                        My install (and every other install that I have used) does not *ever*
                        have it set. My version is (as reported by $_SERVER['SERVER_SOFTWAR E'])
                        "Microsoft-IIS/5.1"
                        [color=blue][color=green]
                        >> Therefore, to be more portable, you may want to do something more like
                        >> this:
                        >>
                        >> if(isset($_GET) && is_array($_GET) && count($_GET)){
                        >> header("HTTP/1.0 404 Not Found");
                        >> echo <<< HTML
                        >> <html>
                        >> <head>
                        >> <title>404 Not Found</title>
                        >> </head>
                        >> <body>
                        >> <h1>Not Found</h1>
                        >> The requested URL was not found on this server.
                        >> </body>
                        >> </html>
                        >> HTML;
                        >> exit;
                        >> }[/color]
                        >
                        > I don't want to sound rude, but that's ridiculous.[/color]

                        ....but you just did.
                        [color=blue]
                        > Just check to see if
                        > $_SERVER["QUERY_STRI NG"] is a non-empty string. If it is, then hey-presto,
                        > you're set. You don't need to call isset, is_array and count all in one go.[/color]

                        And then when you install to another server like Netscape? Zues? AOL?
                        Roxen? thttpd? The list goes on. You cannot *expect* a server to have
                        $_SERVER['QUERY_STRING'] set in all cases.

                        --
                        Justin Koivisto, ZCE - justin@koivi.co m

                        Comment

                        • d

                          #13
                          Re: If isset query_string return 404

                          "Justin Koivisto" <justin@koivi.c om> wrote in message
                          news:3-OdnWt1V_fJm1DeR Vn-ow@onvoy.com...[color=blue]
                          >d wrote:[color=green]
                          >> "Justin Koivisto" <justin@koivi.c om> wrote in message
                          >> news:8fGdnfvFR6 7enVDeRVn-ow@onvoy.com...[color=darkred]
                          >>> d wrote:
                          >>>> "wd" <n23@nospam.inv alid> wrote in message
                          >>>> news:pan.2006.0 1.17.11.23.23.3 21125@nospam.in valid...
                          >>>>> I want my server to send a 404 header if a URL with a query string is
                          >>>>> requested. So if a browser or spider requests something
                          >>>>> like
                          >>>>> www. my_site .com?p=chair
                          >>>>> they would get a 404...
                          >>>>>
                          >>>>> But if they request
                          >>>>> www. my_site .com/chair.htm
                          >>>>> everything would be normal.
                          >>>>>
                          >>>>> With some assistance this is what I have so far, but it isn't working
                          >>>>> correctly. It always displays the 404, even when there is no question
                          >>>>> mark in the URL. Also, I would like the page to stop displaying
                          >>>>> anything
                          >>>>> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
                          >>>>> do
                          >>>>> it:
                          >>>>>
                          >>>>> if (isset($_SERVER["QUERY_STRI NG"])) {
                          >>>>> header("HTTP/1.0 404 Not Found");
                          >>> [snip]
                          >>>
                          >>>> That's because $_SERVER["QUERY_STRI NG"] is *always* set, regardless of
                          >>>> whether there's a query string or not.
                          >>> Not true. With apache, QUERY_STRING will always be set; however, with
                          >>> other web server software (ie. MS IIS) it will never be set unless you
                          >>> have done so yourself.[/color]
                          >>
                          >> Incorrect. I tested it with Apache and IIS. BOTH have
                          >> $_SERVER["QUERY_STRI NG"] set regardless of whether a query string is
                          >> present
                          >> or not.[/color]
                          >
                          > Just because your IIS server has it does not mean that is the default.
                          > My install (and every other install that I have used) does not *ever*
                          > have it set. My version is (as reported by $_SERVER['SERVER_SOFTWAR E'])
                          > "Microsoft-IIS/5.1"[/color]

                          See my other posts.
                          [color=blue][color=green][color=darkred]
                          >>> Therefore, to be more portable, you may want to do something more like
                          >>> this:
                          >>>
                          >>> if(isset($_GET) && is_array($_GET) && count($_GET)){
                          >>> header("HTTP/1.0 404 Not Found");
                          >>> echo <<< HTML
                          >>> <html>
                          >>> <head>
                          >>> <title>404 Not Found</title>
                          >>> </head>
                          >>> <body>
                          >>> <h1>Not Found</h1>
                          >>> The requested URL was not found on this server.
                          >>> </body>
                          >>> </html>
                          >>> HTML;
                          >>> exit;
                          >>> }[/color]
                          >>
                          >> I don't want to sound rude, but that's ridiculous.[/color]
                          >
                          > ...but you just did.
                          >[color=green]
                          >> Just check to see if
                          >> $_SERVER["QUERY_STRI NG"] is a non-empty string. If it is, then
                          >> hey-presto,
                          >> you're set. You don't need to call isset, is_array and count all in one
                          >> go.[/color]
                          >
                          > And then when you install to another server like Netscape? Zues? AOL?
                          > Roxen? thttpd? The list goes on. You cannot *expect* a server to have
                          > $_SERVER['QUERY_STRING'] set in all cases.
                          >
                          > --
                          > Justin Koivisto, ZCE - justin@koivi.co m
                          > http://koivi.com[/color]


                          Comment

                          • Justin Koivisto

                            #14
                            Re: If isset query_string return 404

                            d wrote:[color=blue]
                            >
                            > And not to mention your method only works if the query string is actually a
                            > string of get parameters. If you pass just a string (as in his example),
                            > the $_GET array is empty....[/color]

                            What are you talking about? If you request:
                            example.com/page.php?mystri ng

                            Then the $_GET array will be:
                            array(
                            'mystring' => ""
                            )

                            --
                            Justin Koivisto, ZCE - justin@koivi.co m

                            Comment

                            • d

                              #15
                              Re: If isset query_string return 404

                              "Justin Koivisto" <justin@koivi.c om> wrote in message
                              news:uuydnYNBKY wWmlDenZ2dnUVZ_ s2dnZ2d@onvoy.c om...[color=blue]
                              >d wrote:[color=green]
                              >>
                              >> And not to mention your method only works if the query string is actually
                              >> a
                              >> string of get parameters. If you pass just a string (as in his example),
                              >> the $_GET array is empty....[/color]
                              >
                              > What are you talking about? If you request:
                              > example.com/page.php?mystri ng
                              >
                              > Then the $_GET array will be:
                              > array(
                              > 'mystring' => ""
                              > )[/color]

                              I guess we have differing setups. Either way, your assertion of portability
                              is out of the window ;)
                              [color=blue]
                              > --
                              > Justin Koivisto, ZCE - justin@koivi.co m
                              > http://koivi.com[/color]


                              Comment

                              Working...