|
Posted by d on 09/25/97 11:37
"d" <d@example.com> wrote in message
news:yf6zf.2616$wl.1038@text.news.blueyonder.co.uk...
> "wd" <n23@nospam.invalid> wrote in message
> news:pan.2006.01.17.12.17.01.495568@nospam.invalid...
>> On Tue, 17 Jan 2006 12:06:45 +0000, 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");
>>>> 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_STRING"] 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
>>
>> 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?
>
> No, $_SERVER["QUERY_STRING"] 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_STRING"]=="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
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... ;)
Navigation:
[Reply to this message]
|