Serving web pages: Difference between revisions

From ShawnReevesWiki
Jump to navigationJump to search
No edit summary
Line 28: Line 28:
  allow from all
  allow from all
Put this in the folder where the 403 file is, and it allows even banned IPs access to the 403 error document (and any other files that are in that folder; better add the Files directive also).
Put this in the folder where the 403 file is, and it allows even banned IPs access to the 403 error document (and any other files that are in that folder; better add the Files directive also).
==Getting funny characters right==
Now that I'm starting, like many, to use UTF-8 encoded data, I need to make sure that PHP connects to MySQL using a UTF-8 pipe. That can be accomplished with a single command in PHP scripts:
mysql_set_charset("utf8");


[[Category:Internet]]
[[Category:Internet]]

Revision as of 13:56, 24 February 2012

Stopping spam and hackers

htaccess

An .htaccess file in a directory on a server tells the server how to handle specified requests or requests from specified internet addresses.

Examples of Apache directives

<Files .htaccess>
order allow,deny
deny from all
</Files>

Prevents anyone from reading the .htaccess file(s).

order allow,deny
deny from 59.92.4.185
deny from 66.225.201
deny from 69.80.96.0/20
allow from all

Prevents anyone from 59.92.4.185, addresses that start with 66.225.201, or addresses that match the first 20 bits of 69.80.96.0.

ErrorDocument 403 "Sorry, requests from your IP address are forbidden

Shows the phrase after " when access is denied to a page.

ErrorDocument 403 /errors/403.html

Replies with the 403.html file when access is denied to a page.

ErrorDocument 404 /errors/404.html

Replies with the 404.html file when the request can't be found.

order allow,deny 
allow from all

Put this in the folder where the 403 file is, and it allows even banned IPs access to the 403 error document (and any other files that are in that folder; better add the Files directive also).

Getting funny characters right

Now that I'm starting, like many, to use UTF-8 encoded data, I need to make sure that PHP connects to MySQL using a UTF-8 pipe. That can be accomplished with a single command in PHP scripts:

mysql_set_charset("utf8");