You are here: Re: If isset query_string return 404 « PHP Programming Language « IT news, forums, messages
Re: If isset query_string return 404

Posted by d on 09/27/92 11:37

"Justin Koivisto" <justin@koivi.com> wrote in message
news:8fGdnfvFR67enVDeRVn-ow@onvoy.com...
>d wrote:
>> "wd" <n23@nospam.invalid> wrote in message
>> news:pan.2006.01.17.11.23.23.321125@nospam.invalid...
>>> 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_STRING"])) {
>>> header("HTTP/1.0 404 Not Found");
>
> [snip]
>
>> That's because $_SERVER["QUERY_STRING"] 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.

Incorrect. I tested it with Apache and IIS. BOTH have
$_SERVER["QUERY_STRING"] set regardless of whether a query string is present
or not.

> 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;
> }

I don't want to sound rude, but that's ridiculous. Just check to see if
$_SERVER["QUERY_STRING"] 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.

> --
> Justin Koivisto, ZCE - justin@koivi.com
> http://koivi.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация